00001 00008 #include "jobpropertyitemstring.h" 00009 #include <QLineEdit> 00010 #include <QRegExpValidator> 00011 00019 JobPropertyItemString::JobPropertyItemString(JobPropertyModel * model, QString inName, JobPropertyItem *parent) 00020 :JobPropertyItem(model) 00021 { 00022 _name = inName; 00023 parentItem = parent; 00024 QVector<QVariant> data; 00025 data << _name << ""; 00026 itemData = data; 00027 } 00028 00032 JobPropertyItemString::~JobPropertyItemString() 00033 {} 00034 00041 bool JobPropertyItemString::setData(int column, const QVariant &value) 00042 { 00043 if (column < 1 || column >= itemData.size()) 00044 return false; 00045 00046 itemData[column] = value; 00047 return true; 00048 } 00049 00050 00058 QWidget *JobPropertyItemString::createEditor(QWidget *parent, const QObject *target, const char *receiver) const 00059 { 00060 QLineEdit * strEditor = new QLineEdit(parent); 00061 if (!_rx.isEmpty()) 00062 strEditor->setValidator(static_cast<QValidator*>(new QRegExpValidator(_rx, strEditor))); 00063 00064 QObject::connect(strEditor, SIGNAL(textChanged(QString)), target, receiver); 00065 return strEditor; 00066 } 00067 00073 void JobPropertyItemString::updateEditorContents(QWidget *editor) 00074 { 00075 QLineEdit * lineEditor = qobject_cast<QLineEdit *>(editor); 00076 QString value = itemData[1].toString(); 00077 lineEditor->setText(value); 00078 } 00079 00085 void JobPropertyItemString::updateValue(QWidget *editor) 00086 { 00087 QLineEdit * lineEditor = qobject_cast<QLineEdit *>(editor); 00088 QString newValue = lineEditor->text(); 00089 if (newValue != itemData[1]) 00090 { 00091 itemData[1] = newValue; 00092 emit itemChanged(newValue); 00093 emit jobPropertyChanged(itemData); 00094 } 00095 } 00096 00102 void JobPropertyItemString::set(const QString & str) 00103 { 00104 QString curvalue = itemData[1].toString(); 00105 if (curvalue != str) 00106 { 00107 _model->emitLayoutAboutToBeChanged(); 00108 itemData[1] = str; 00109 _model->emitLayoutChanged(); 00110 } 00111 } 00112 00118 void JobPropertyItemString::setRegExpValidator(QRegExp rx) 00119 { 00120 _rx = rx; 00121 } 00122 00126 QString JobPropertyItemString::toString() 00127 { 00128 return itemData[1].toString(); 00129 }