ModelManagerWizard.ui.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 namespace dummy_namespace_to_avoid_gcc411_bug_ModelManagerWizard_ui_h
00019 {
00020 typedef std::map<const ModelOptionCateg*, ModelManagerWizardItem> categs_type;
00021
00022 struct DefInfo
00023 {
00024 int ypos;
00025 };
00026 }
00027
00028 using namespace dummy_namespace_to_avoid_gcc411_bug_ModelManagerWizard_ui_h;
00029
00030 class ModelManagerWizardItem
00031 {
00032 public:
00033 ModelManagerWizardItem() :
00034 lbitem(0), sv(0), count(0)
00035 {}
00036
00037 QListBoxItem* lbitem;
00038 QScrollView* sv;
00039 std::map<const ModelOptionDef*, DefInfo> defs;
00040 int count;
00041 };
00042
00043 void ModelManagerWizard::init(ModelManager & manager)
00044 {
00045 errBox = new QErrorMessage(this);
00046 mgr = &manager;
00047 mgr->writeParamsTo(backupMap);
00048 refreshOptions();
00049 }
00050
00051 void ModelManagerWizard::refreshOptions(void)
00052 {
00053 currentSv = 0;
00054 categs.clear();
00055 listbox->clear();
00056 listbox->triggerUpdate(false);
00057
00058 const uint ndefs = mgr->numOptionDefs();
00059
00060 const ModelOptionDef* defs[ndefs];
00061
00062 const uint nfilled = mgr->getOptionDefs(defs, ndefs);
00063
00064
00065 for (uint i = 0; i < nfilled; ++i)
00066 {
00067 const ModelOptionDef* def = defs[i];
00068
00069 if (!mgr->isOptionDefUsed(def))
00070 continue;
00071
00072 if (categs.find(def->categ) == categs.end())
00073 {
00074 ModelManagerWizardItem newitem;
00075
00076 newitem.lbitem =
00077 new QListBoxText(listbox, def->categ->description);
00078
00079 newitem.sv = new QScrollView(this);
00080 newitem.sv->setHScrollBarMode(QScrollView::AlwaysOff);
00081 newitem.sv->setGeometry(260, 10, 500, 420);
00082 newitem.sv->viewport()->setPaletteBackgroundColor(this->paletteBackgroundColor());
00083 newitem.sv->enableClipper(true);
00084 newitem.sv->hide();
00085
00086 categs.insert(categs_type::value_type(def->categ, newitem));
00087 }
00088
00089 ModelManagerWizardItem& item = categs[def->categ];
00090 ASSERT(item.lbitem != 0);
00091 ASSERT(item.sv != 0);
00092
00093 item.defs[def].ypos = 20 + 40 * item.count;
00094
00095
00096 QLabel* label = new QLabel(def->longoptname, item.sv->viewport());
00097 label->adjustSize();
00098 QWhatsThis::add(label, def->descr);
00099 item.sv->addChild(label, 20, item.defs[def].ypos);
00100
00101
00102 const std::type_info* argtype = def->type.argtype;
00103
00104 if (argtype != 0 && *argtype == typeid(bool))
00105 {
00106 QCheckBox* cb = new QCheckBox(item.sv->viewport(), def->name);
00107 cb->setChecked(fromStr<bool>(mgr->getOptionValString(def)));
00108 connect(cb, SIGNAL(toggled(bool)),
00109 this, SLOT(handleCheckBox(bool)));
00110 itsWidgetOptions[cb] = def;
00111 item.sv->addChild(cb, 300, item.defs[def].ypos);
00112 }
00113 else
00114 {
00115
00116 QLineEdit* le = new QLineEdit(item.sv->viewport(), def->name);
00117 le->setText(mgr->getOptionValString(def));
00118 connect(le, SIGNAL(lostFocus(void)),
00119 this, SLOT(handleLineEdit(void)));
00120 itsWidgetOptions[le] = def;
00121 item.sv->addChild(le, 300, item.defs[def].ypos);
00122 }
00123
00124 ++item.count;
00125 item.sv->resizeContents(400, 20 + item.defs[def].ypos);
00126 }
00127
00128 QListBoxItem* first = listbox->item(0);
00129 listbox->setCurrentItem(first);
00130 showFrame(first);
00131 }
00132
00133 void ModelManagerWizard::showFrame(QListBoxItem* item)
00134 {
00135 for (categs_type::iterator itr = categs.begin();
00136 itr != categs.end(); ++itr)
00137 if ((*itr).second.lbitem == item)
00138 {
00139
00140 if (currentSv != 0) currentSv->hide();
00141 currentSv = (*itr).second.sv;
00142 currentSv->show();
00143
00144 const int index = listbox->index((*itr).second.lbitem);
00145
00146
00147 if (index == 0) backButton->hide();
00148 else backButton->show();
00149
00150
00151 if (index == listbox->numRows() - 1) nextButton->hide();
00152 else nextButton->show();
00153 }
00154 }
00155
00156
00157
00158 void ModelManagerWizard::handleCancelButton(void)
00159 {
00160 mgr->readParamsFrom(backupMap);
00161 close();
00162 }
00163
00164 void ModelManagerWizard::handleBackButton(void)
00165 {
00166 listbox->setCurrentItem(listbox->currentItem() - 1);
00167 showFrame(listbox->selectedItem());
00168 }
00169
00170 void ModelManagerWizard::handleNextButton(void)
00171 {
00172 listbox->setCurrentItem(listbox->currentItem() + 1);
00173 showFrame(listbox->selectedItem());
00174 }
00175
00176 void ModelManagerWizard::handleFinishButton(void)
00177 {
00178 close();
00179 }
00180
00181
00182 void ModelManagerWizard::handleCheckBox(bool b)
00183 {
00184 const QCheckBox* box = dynamic_cast<const QCheckBox*>(sender());
00185 ASSERT(box != 0);
00186
00187 const ModelOptionDef* def = itsWidgetOptions[box];
00188 ASSERT(def != 0);
00189
00190 try
00191 {
00192 mgr->setOptionValString(def, toStr(b));
00193 }
00194 catch (std::exception& e)
00195 {
00196 errBox->message(e.what());
00197 }
00198 refreshAndSelect(sender()->name(), def);
00199 }
00200
00201 void ModelManagerWizard::handleLineEdit(void)
00202 {
00203 const QLineEdit* line = dynamic_cast<const QLineEdit*>(sender());
00204 ASSERT(line != 0);
00205
00206 const ModelOptionDef* def = itsWidgetOptions[line];
00207 ASSERT(def != 0);
00208
00209 try
00210 {
00211 mgr->setOptionValString(def, line->text().latin1());
00212 }
00213 catch (std::exception& e)
00214 {
00215 errBox->message(e.what());
00216 }
00217 refreshAndSelect(sender()->name(), def);
00218 }
00219
00220 void ModelManagerWizard::refreshAndSelect(QString sel,
00221 const ModelOptionDef* def)
00222 {
00223
00224 refreshOptions();
00225
00226
00227 categs_type::iterator itr = categs.find(def->categ);
00228 ASSERT(itr != categs.end());
00229
00230
00231 listbox->setCurrentItem((*itr).second.lbitem);
00232 showFrame((*itr).second.lbitem);
00233
00234
00235 (*itr).second.sv->ensureVisible(300, (*itr).second.defs[def].ypos);
00236 }