00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00025
00026
00027
00029
00030
00031 #include <cassert>
00032
00033
00034 #include <qbuttongroup.h>
00035 #include <qcheckbox.h>
00036 #include <qcombobox.h>
00037 #include <qdir.h>
00038 #include <qdom.h>
00039 #include <qfiledialog.h>
00040 #include <qlineedit.h>
00041 #include <qpushbutton.h>
00042 #include <qradiobutton.h>
00043 #include <qstring.h>
00044 #include <qtoolbutton.h>
00045
00046
00047 #include "domutils.h"
00048 #include "globalbase.h"
00049 #include "iconsets.h"
00050 #include "latin1validator.h"
00051
00052
00056
00058 GlobalBase::GlobalBase(QWidget* parent, const char* name, bool modal, WFlags fl) : GlobalWidget(parent, name, modal, fl)
00060 {
00061 ButtonGroupRunType->hide();
00062 CheckBoxBuur->hide();
00063 ComboBoxBuur->hide();
00064 ToolButtonDir->setIconSet(IconSets::getIconSet(IconSets::Open));
00065 resize(minimumSize());
00066 makeConnections();
00067
00068 }
00069
00071 GlobalBase::~GlobalBase()
00073 {
00074
00075 }
00076
00078 void GlobalBase::setDefaultName(const QString name)
00080 {
00081 defaultName = name;
00082 init();
00083 }
00084
00086 unsigned int GlobalBase::calculationType() const
00092 {
00093 return data.type;
00094 }
00095
00097 unsigned int GlobalBase::buurType() const
00102 {
00103 if(!data.useBuur)
00104 return NoBuur;
00105 else
00106 return data.buurType + 1;
00107 }
00108
00110 bool GlobalBase::extendedFormat() const
00112 {
00113 return data.useXF;
00114 }
00115
00117 QString GlobalBase::description() const
00119 {
00120 return data.description;
00121 }
00122
00124 QString GlobalBase::name() const
00126 {
00127 return data.name;
00128 }
00129
00131 QString GlobalBase::directory() const
00133 {
00134 return data.directory;
00135 }
00136
00138 unsigned int GlobalBase::runType() const
00143 {
00144 return data.runType;
00145 }
00146
00148 unsigned int GlobalBase::queue() const
00150 {
00151 return data.queue;
00152 }
00153
00155 void GlobalBase::allowChanges(const bool status)
00158 {
00159 GroupBoxType->setEnabled(status);
00160 LineEditName->setEnabled(status);
00161 LineEditDir->setEnabled(status);
00162 ToolButtonDir->setEnabled(status);
00163 }
00164
00166 void GlobalBase::loadCML(const QDomElement* root)
00168 {
00171 assert(!isVisible());
00172
00173 const QString prefix = "global_";
00174 QDomNode childNode = root->firstChild();
00175 while(!childNode.isNull())
00176 {
00177 if(childNode.isElement() && childNode.toElement().tagName() == "parameter")
00178 {
00179 if(DomUtils::dictEntry(childNode, prefix + "calculation_type"))
00180 DomUtils::readNode(&childNode, &data.type);
00181
00182
00183
00184
00185 else if(DomUtils::dictEntry(childNode, prefix + "use_extended_format"))
00186 DomUtils::readNode(&childNode, &data.useXF);
00187 else if(DomUtils::dictEntry(childNode, prefix + "description"))
00188 DomUtils::readNode(&childNode, &data.description);
00189 else if(DomUtils::dictEntry(childNode, prefix + "name"))
00190 DomUtils::readNode(&childNode, &data.name);
00191 else if(DomUtils::dictEntry(childNode, prefix + "directory"))
00192 DomUtils::readNode(&childNode, &data.directory);
00193
00194
00195
00196
00197 }
00198 childNode = childNode.nextSibling();
00199 }
00200 restoreWidgets();
00201 }
00202
00204 void GlobalBase::saveCML(QDomElement* root)
00206 {
00209 assert(!isVisible());
00210
00212 const QString prefix = "global_";
00213 DomUtils::makeNode(root, data.type, prefix + "calculation_type");
00214
00215
00216 DomUtils::makeNode(root, data.useXF, prefix + "use_extended_format");
00217 DomUtils::makeNode(root, data.description, prefix + "description");
00218 DomUtils::makeNode(root, data.name, prefix + "name");
00219 DomUtils::makeNode(root, data.directory, prefix + "directory");
00220
00221
00222
00223 }
00224
00228
00230 void GlobalBase::reset()
00232 {
00233 LineEditDesc->clear();
00234
00235 if(!GroupBoxType->isEnabled())
00236 return;
00237
00238 ComboBoxType->setCurrentItem(SinglePointEnergy);
00239
00240
00241 CheckBoxBuur->setChecked(false);
00242 ComboBoxBuur->setCurrentItem(NoBuur);
00243 CheckBoxXF->setChecked(true);
00244
00245 LineEditName->setText(defaultName);
00246 LineEditDir->setText(QDir::convertSeparators(QDir::homeDirPath()) + QDir::separator() + defaultName);
00247
00248 RadioButtonRun1->setChecked(true);
00249 ComboBoxQueue->setCurrentItem(0);
00250 }
00251
00252
00256
00258 void GlobalBase::accept()
00260 {
00262
00263
00264
00265 if(widgetChanged)
00266 {
00267 setChanged(false);
00268 saveWidgets();
00269 GlobalWidget::accept();
00270 }
00271 else
00272 GlobalWidget::reject();
00273 }
00274
00276 void GlobalBase::reject()
00278 {
00279 if(widgetChanged)
00280 {
00281 setChanged(false);
00282 restoreWidgets();
00283 }
00284 GlobalWidget::reject();
00285 }
00286
00287
00291
00293 void GlobalBase::setChanged(const bool state)
00296 {
00297 widgetChanged = state;
00298 }
00299
00301 void GlobalBase::correctType(int index)
00304 {
00305 if(index > 2)
00306 ComboBoxType->setCurrentItem(2);
00307 }
00308
00310 void GlobalBase::chooseDir()
00312 {
00313 QString newDir = QFileDialog::getExistingDirectory(LineEditDir->text(),this,0,tr("Choose a directory"));
00314 if(!newDir.isNull())
00315 LineEditDir->setText(QDir::convertSeparators(newDir));
00316 }
00317
00318
00322
00324 void GlobalBase::makeConnections()
00326 {
00328 connect(ButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
00329 connect(ButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00330 connect(ButtonReset, SIGNAL(clicked()), this, SLOT(reset()));
00332 connect(CheckBoxBuur, SIGNAL(toggled(bool)), ComboBoxBuur, SLOT(setEnabled(bool)));
00333 connect(ToolButtonDir, SIGNAL(clicked()), this, SLOT(chooseDir()));
00334 connect(RadioButtonRun3, SIGNAL(toggled(bool)), ComboBoxQueue, SLOT(setEnabled(bool)));
00336 connect(ComboBoxType, SIGNAL(activated(int)), this, SLOT(correctType(int)));
00338 connect(ComboBoxType, SIGNAL(activated(int)), this, SLOT(setChanged()));
00339 connect(CheckBoxBuur, SIGNAL(clicked()), this, SLOT(setChanged()));
00340 connect(ComboBoxBuur, SIGNAL(activated(int)), this, SLOT(setChanged()));
00341 connect(CheckBoxXF, SIGNAL(clicked()), this, SLOT(setChanged()));
00342 connect(LineEditDesc, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
00343 connect(LineEditName, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
00344 connect(LineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
00345 connect(ButtonGroupRunType, SIGNAL(clicked(int)), this, SLOT(setChanged()));
00346 connect(ComboBoxQueue, SIGNAL(activated(int)), this, SLOT(setChanged()));
00347 }
00348
00350 void GlobalBase::init()
00352 {
00353
00354 LineEditName->setValidator(new Latin1Validator(this));
00355
00356 reset();
00357 saveWidgets();
00358 widgetChanged = false;
00359 }
00360
00362 void GlobalBase::saveWidgets()
00364 {
00365 data.type = ComboBoxType->currentItem();
00366 data.useBuur = CheckBoxBuur->isOn();
00367 data.buurType = ComboBoxBuur->currentItem();
00368 data.useXF = CheckBoxXF->isOn();
00369
00370 data.description = LineEditDesc->text();
00371 data.name = LineEditName->text();
00372 data.directory = LineEditDir->text();
00373
00374
00375 if(RadioButtonRun1->isChecked())
00376 data.runType = 0;
00377 if(RadioButtonRun2->isChecked())
00378 data.runType = 1;
00379 if(RadioButtonRun3->isChecked())
00380 data.runType = 3;
00381 data.queue = ComboBoxQueue->currentItem();
00382 }
00383
00385 void GlobalBase::restoreWidgets()
00387 {
00388 ComboBoxType->setCurrentItem(data.type);
00389 CheckBoxBuur->setChecked(data.useBuur);
00390 ComboBoxBuur->setCurrentItem(data.buurType);
00391 CheckBoxXF->setChecked(data.useXF);
00392
00393 LineEditDesc->setText(data.description);
00394 LineEditName->setText(data.name);
00395 LineEditDir->setText(data.directory);
00396
00397
00398 switch(data.runType)
00399 {
00400 case 0: RadioButtonRun1->setChecked(true);
00401 break;
00402 case 1: RadioButtonRun2->setChecked(true);
00403 break;
00404 case 2: RadioButtonRun3->setChecked(true);
00405 break;
00406 }
00407 ComboBoxQueue->setCurrentItem(data.queue);
00408 }
00409