src/job_editor_widget/jobpropertyitem.cpp

Go to the documentation of this file.
00001 
00008 #include <QDebug>
00009 #include "jobpropertyitem.h"
00010 #include "jobpropertyitemstring.h"
00011 #include "jobpropertyitemnodes.h"
00012 
00013 
00014 // ---------------------- JobPropertyItem ----------------------- //
00015 
00021 JobPropertyItem::JobPropertyItem(JobPropertyModel * model)
00022         : QObject(), parentItem(0),
00023         _name(QString("")),
00024         _model(model),
00025         _isreadonly(false), _hascontextmenu(false)
00026 {}
00027 
00033 JobPropertyItem *JobPropertyItem::child(int number)
00034 {
00035     return childItems.value(number);
00036 }
00037 
00041 int JobPropertyItem::childCount() const
00042 {
00043     return childItems.count();
00044 }
00045 
00049 int JobPropertyItem::childNumber() const
00050 {
00051     if (parentItem)
00052         return parentItem->childItems.indexOf(const_cast<JobPropertyItem*>(this));
00053     return 0;
00054 }
00055 
00059 JobPropertyItem *JobPropertyItem::parent()
00060 {
00061     return parentItem;
00062 }
00063 
00067 int JobPropertyItem::columnCount() const
00068 {
00069     return itemData.count();
00070 }
00071 
00077 QVariant JobPropertyItem::data(int column) const
00078 {
00079     if (column<itemData.count() &&column>=0)
00080         return itemData[column];
00081     else
00082             return QVariant();
00083 }
00084 
00091 bool JobPropertyItem::setData(int column, const QVariant &value)
00092 {
00093     if (!_isreadonly && column<itemData.count() &&column>=0)
00094     {
00095         itemData[column] = value;
00096         return true;
00097     }
00098     return false;
00099 }
00100 
00106 void JobPropertyItem::setHaveContextMenu(bool b)
00107 {
00108     _hascontextmenu = b;
00109 }
00110 
00114 bool JobPropertyItem::hasContextMenu() const
00115 {
00116     return _hascontextmenu;
00117 }
00118 
00124 void JobPropertyItem::setReadOnly(bool b)
00125 {
00126     _isreadonly = b;
00127 }
00128 
00132 bool JobPropertyItem::isReadOnly() const
00133 {
00134     return _isreadonly;
00135 }
00136 
00143 void JobPropertyItem::createCustomContextMenu(QWidget *parent, const QPoint & pos)
00144 {
00145     Q_UNUSED(parent);
00146     Q_UNUSED(pos);
00147 }
00148 
00154 bool JobPropertyItem::deleteChild(int row)
00155 {
00156     Q_UNUSED(row);
00157     return false;
00158 }
00159 
00163 QModelIndex JobPropertyItem::getSelfIndex()
00164 {
00165     if (parentItem)
00166         return _model->index(childNumber(), 0, parentItem->getSelfIndex());
00167     return QModelIndex();
00168 }
00169 
00170 
00171 // -------------------- JobPropertyItemRoot --------------------- //
00178 JobPropertyItemRoot::JobPropertyItemRoot(JobPropertyModel * model,JobPropertyItem *parent)
00179         :JobPropertyItem(model)
00180 {
00181     QVector<QVariant> data;
00182     JobPropertyItemString * strItem;
00183     JobPropertyItemNodes * nodesItem;
00184 
00185     data << tr("Property") << tr("Value");
00186     itemData = data;
00187     parentItem = parent;
00188 
00189     //TODO: some RegExpValidators
00190 
00191     strItem = new JobPropertyItemString(_model, tr("Output file (-o)"),this);
00192     childItems.append(static_cast<JobPropertyItem *>(strItem));
00193 
00194     strItem = new JobPropertyItemString(_model, tr("Error file (-e)"),this);
00195     childItems.append(static_cast<JobPropertyItem *>(strItem));
00196 
00197     strItem = new JobPropertyItemString(_model, tr("join (-j)"),this);
00198     strItem->setRegExpValidator(QRegExp("(oe|eo|n)"));
00199     childItems.append(static_cast<JobPropertyItem *>(strItem));
00200 
00201     strItem = new JobPropertyItemString(_model, tr("Mail (-M)"),this);
00202     childItems.append(static_cast<JobPropertyItem *>(strItem));
00203 
00204     strItem = new JobPropertyItemString(_model, tr("Name (-N)"),this);
00205     strItem->setRegExpValidator(QRegExp("([A-Z,a-z]\\S{,14})"));
00206     childItems.append(static_cast<JobPropertyItem *>(strItem));
00207 
00208     strItem = new JobPropertyItemString(_model, tr("Walltime"),this);
00209     strItem->setRegExpValidator(QRegExp("(\\d+|\\d+:\\d+|\\d+:\\d+:\\d+)"));
00210     childItems.append(static_cast<JobPropertyItem *>(strItem));
00211 
00212     nodesItem = new JobPropertyItemNodes(_model, this);
00213     childItems.append(static_cast<JobPropertyItem *>(nodesItem));
00214 
00215     strItem = new JobPropertyItemString(_model, QString("nice"),this);
00216     strItem->setRegExpValidator(QRegExp("(-?[0-2]?\\d)"));
00217     childItems.append(static_cast<JobPropertyItem *>(strItem));
00218 
00219     strItem = new JobPropertyItemString(_model, QString("cput"),this);
00220     strItem->setRegExpValidator(QRegExp("(\\d+|\\d+:\\d+|\\d+:\\d+:\\d+)"));
00221     childItems.append(static_cast<JobPropertyItem *>(strItem));
00222 
00223     strItem = new JobPropertyItemString(_model, QString("pcput"),this);
00224     strItem->setRegExpValidator(QRegExp("(\\d+|\\d+:\\d+|\\d+:\\d+:\\d+)"));
00225     childItems.append(static_cast<JobPropertyItem *>(strItem));
00226 
00227     strItem = new JobPropertyItemString(_model, QString("file"),this);
00228     strItem->setRegExpValidator(QRegExp("(\\d+[kmgt]?[bw]?)"));
00229     childItems.append(static_cast<JobPropertyItem *>(strItem));
00230 
00231     strItem = new JobPropertyItemString(_model, QString("mem"),this);
00232     strItem->setRegExpValidator(QRegExp("(\\d+[kmgt]?[bw]?)"));
00233     childItems.append(static_cast<JobPropertyItem *>(strItem));
00234 
00235     strItem = new JobPropertyItemString(_model, QString("pmem"),this);
00236     strItem->setRegExpValidator(QRegExp("(\\d+[kmgt]?[bw]?)"));
00237     childItems.append(static_cast<JobPropertyItem *>(strItem));
00238 
00239     strItem = new JobPropertyItemString(_model, QString("vmem"),this);
00240     strItem->setRegExpValidator(QRegExp("(\\d+[kmgt]?[bw]?)"));
00241     childItems.append(static_cast<JobPropertyItem *>(strItem));
00242 
00243     strItem = new JobPropertyItemString(_model, QString("pvmem"),this);
00244     strItem->setRegExpValidator(QRegExp("(\\d+[kmgt]?[bw]?)"));
00245     childItems.append(static_cast<JobPropertyItem *>(strItem));
00246 
00247     strItem = new JobPropertyItemString(_model, QString("arch"),this);
00248     childItems.append(static_cast<JobPropertyItem *>(strItem));
00249 
00250     strItem = new JobPropertyItemString(_model, QString("host"),this);
00251     childItems.append(static_cast<JobPropertyItem *>(strItem));
00252 
00253     strItem = new JobPropertyItemString(_model, QString("other"),this);
00254     childItems.append(static_cast<JobPropertyItem *>(strItem));
00255 
00256     strItem = new JobPropertyItemString(_model, QString("opsys"),this);
00257     childItems.append(static_cast<JobPropertyItem *>(strItem));
00258 
00259     strItem = new JobPropertyItemString(_model, QString("software"),this);
00260     childItems.append(static_cast<JobPropertyItem *>(strItem));
00261 
00262     setReadOnly(true);
00263 }
00264 
00268 JobPropertyItemRoot::~JobPropertyItemRoot()
00269 {
00270     qDeleteAll(childItems);
00271 }
00272 
00280 QWidget * JobPropertyItemRoot::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
00281 {
00282     Q_UNUSED(target);
00283     Q_UNUSED(receiver);
00284     return new QWidget(parent);
00285 }
00286 
00292 void JobPropertyItemRoot::updateEditorContents(QWidget *editor)
00293 {
00294     Q_UNUSED(editor);
00295 }
00296 
00302 void JobPropertyItemRoot::updateValue(QWidget *editor)
00303 {
00304     Q_UNUSED(editor);
00305 }
00306 
00307 
00308 
00314 void JobPropertyItemRoot::setWalltime(const QString & walltime)
00315 {
00316     childItems[0]->setData(1, walltime);
00317 }
00318 
00324 void JobPropertyItemRoot::setNodes(const QString & nodes)
00325 {
00326     childItems[1]->setData(1, nodes);
00327 }
00328 

Generated on Mon Mar 16 18:46:05 2009 for QCJM by  doxygen 1.5.4