Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/QT4/QTDialog.cpp

    r992fd7 rcd8e55  
    2121#include <Qt/qcombobox.h>
    2222
     23#include "Helpers/MemDebug.hpp"
     24
    2325#include "World.hpp"
    2426#include "periodentafel.hpp"
     
    2628#include "element.hpp"
    2729#include "molecule.hpp"
    28 #include "Helpers/MemDebug.hpp"
     30#include "Descriptors/MoleculeIdDescriptor.hpp"
    2931
    3032
     
    7678/************************** Query Infrastructure ************************/
    7779
    78 void QTDialog::queryInt(const char *title, int *target)
     80void QTDialog::queryEmpty(char const*, string){
     81  // TODO
     82  ASSERT(false, "Not implemented yet");
     83}
     84
     85void QTDialog::queryBoolean(char const*, bool*,string){
     86  // TODO
     87  ASSERT(false, "Not implemented yet");
     88}
     89
     90void QTDialog::queryAtom(char const*, atom**, string){
     91  // TODO
     92  ASSERT(false, "Not implemented yet");
     93}
     94
     95void QTDialog::queryBox(char const*, double**, string){
     96  // TODO
     97  ASSERT(false, "Not implemented yet");
     98}
     99
     100
     101void QTDialog::queryInt(const char *title, int *target,string)
    79102{
    80103  registerQuery(new IntQTQuery(title,target,inputLayout,this));
    81104}
    82105
    83 void QTDialog::queryDouble(const char* title, double* target){
     106void QTDialog::queryDouble(const char* title, double* target,string){
    84107  registerQuery(new DoubleQTQuery(title,target,inputLayout,this));
    85108}
    86109
    87 void QTDialog::queryString(const char* title, std::string *target)
     110void QTDialog::queryString(const char* title, std::string *target,string)
    88111{
    89112  registerQuery(new StringQTQuery(title,target,inputLayout,this));
    90113}
    91114
    92 void QTDialog::queryMolecule(const char *title,molecule **target,MoleculeListClass *molecules)
    93 {
    94   registerQuery(new MoleculeQTQuery(title,target,molecules,inputLayout,this));
    95 }
    96 
    97 void QTDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) {
     115void QTDialog::queryStrings(const char* title, std::vector<std::string> *target,string)
     116{
     117  registerQuery(new StringsQTQuery(title,target,inputLayout,this));
     118}
     119
     120void QTDialog::queryMolecule(const char *title,molecule **target,string)
     121{
     122  registerQuery(new MoleculeQTQuery(title,target,inputLayout,this));
     123}
     124
     125void QTDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check,string) {
    98126  registerQuery(new VectorQTQuery(title,target,cellSize,check,inputLayout,this));
    99127}
    100128
    101 void QTDialog::queryElement(const char* title, const element **target){
     129void QTDialog::queryElement(const char* title, std::vector<element *> *target,string){
    102130  registerQuery(new ElementQTQuery(title,target,inputLayout,this));
    103131}
     
    189217}
    190218
    191 QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, MoleculeListClass *_molecules, QBoxLayout *_parent,QTDialog *_dialog) :
    192     Dialog::MoleculeQuery(_title,_target,_molecules),
    193     parent(_parent)
    194 {
    195   MoleculeList::iterator iter;
     219QTDialog::StringsQTQuery::StringsQTQuery(string _title,vector<string> *_target,QBoxLayout *_parent,QTDialog *_dialog) :
     220    Dialog::StringsQuery(_title,_target),
     221    parent(_parent)
     222{
     223  thisLayout = new QHBoxLayout();
     224  titleLabel = new QLabel(QString(getTitle().c_str()));
     225  inputBox = new QLineEdit();
     226  parent->addLayout(thisLayout);
     227  thisLayout->addWidget(titleLabel);
     228  thisLayout->addWidget(inputBox);
     229
     230  pipe = new StringQTQueryPipe(&temp,_dialog);
     231  pipe->update(inputBox->text());
     232  connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
     233}
     234
     235QTDialog::StringsQTQuery::~StringsQTQuery()
     236{
     237  delete pipe;
     238}
     239
     240// All values besides the empty string are valid
     241bool QTDialog::StringsQTQuery::handle()
     242{
     243  // dissect by ","
     244  string::iterator olditer = temp.begin();
     245  for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
     246    if (*iter == ' ') {
     247      tmp.push_back(string(iter, olditer));
     248      olditer = iter;
     249    }
     250  }
     251  if (olditer != temp.begin())  // insert last part also
     252    tmp.push_back(string(olditer, temp.end()));
     253
     254  return temp!="";
     255}
     256
     257QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, QBoxLayout *_parent,QTDialog *_dialog) :
     258    Dialog::MoleculeQuery(_title,_target),
     259    parent(_parent)
     260{
    196261  thisLayout = new QHBoxLayout();
    197262  titleLabel = new QLabel(QString(getTitle().c_str()));
    198263  inputBox = new QComboBox();
    199264  // add all molecules to the combo box
    200   for(iter  = molecules->ListOfMolecules.begin();
    201       iter != molecules->ListOfMolecules.end();
     265  vector<molecule*> molecules = World::getInstance().getAllMolecules();
     266  for(vector<molecule*>::iterator iter  = molecules.begin();
     267      iter != molecules.end();
    202268      ++iter) {
    203269    stringstream sstr;
     
    209275  thisLayout->addWidget(inputBox);
    210276
    211   pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox,_molecules);
     277  pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
    212278  pipe->update(inputBox->currentIndex());
    213279  connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
     
    263329
    264330
    265 QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, const element **_target, QBoxLayout *_parent, QTDialog *_dialog) :
     331QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, vector<element *> *_target, QBoxLayout *_parent, QTDialog *_dialog) :
    266332    Dialog::ElementQuery(_title,_target),
    267333    parent(_parent)
     
    283349  thisLayout->addWidget(inputBox);
    284350
    285   pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox);
     351  pipe = new ElementQTQueryPipe(&elements,_dialog,inputBox);
    286352  pipe->update(inputBox->currentIndex());
    287353  connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
     
    338404}
    339405
    340 MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox, MoleculeListClass *_molecules) :
     406MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
    341407  content(_content),
    342408  dialog(_dialog),
    343   theBox(_theBox),
    344   molecules(_molecules)
     409  theBox(_theBox)
    345410{}
    346411
     
    351416  QVariant data = theBox->itemData(newIndex);
    352417  int idx = data.toInt();
    353   (*content) = molecules->ReturnIndex(idx);
     418  (*content) = World::getInstance().getMolecule(MoleculeById(idx));
    354419  dialog->update();
    355420}
    356421
    357 ElementQTQueryPipe::ElementQTQueryPipe(const element **_content, QTDialog *_dialog, QComboBox *_theBox) :
     422ElementQTQueryPipe::ElementQTQueryPipe(std::vector<element *> *_content, QTDialog *_dialog, QComboBox *_theBox) :
    358423  content(_content),
    359424  dialog(_dialog),
    360425  theBox(_theBox)
    361 {}
     426{
     427  content->resize(1);
     428}
    362429
    363430ElementQTQueryPipe::~ElementQTQueryPipe()
     
    367434  QVariant data = theBox->itemData(newIndex);
    368435  int idx = data.toInt();
    369   (*content) = World::getInstance().getPeriode()->FindElement(idx);
     436  (*content)[0] = World::getInstance().getPeriode()->FindElement(idx);
    370437  dialog->update();
    371438}
Note: See TracChangeset for help on using the changeset viewer.