| [8df74d] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /*
 | 
|---|
 | 9 |  * StringsQtQuery.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Oct 25, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include <Qt/qboxlayout.h>
 | 
|---|
 | 21 | #include <Qt/qlabel.h>
 | 
|---|
 | 22 | #include <Qt/qlineedit.h>
 | 
|---|
 | 23 | #include <Qt/qlistwidget.h>
 | 
|---|
 | 24 | #include <Qt/qpushbutton.h>
 | 
|---|
 | 25 | 
 | 
|---|
| [ad011c] | 26 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [8df74d] | 27 | 
 | 
|---|
| [308aa4] | 28 | #include "UIElements/Qt4/Query/QtQuery.hpp"
 | 
|---|
| [8df74d] | 29 | #include "UIElements/Qt4/Pipe/QtQueryListPipe.hpp"
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | QtDialog::StringsQtQuery::StringsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
 | 
|---|
 | 33 |     Dialog::StringsQuery(_title),
 | 
|---|
 | 34 |     parent(_parent)
 | 
|---|
 | 35 | {
 | 
|---|
 | 36 |   QHBoxLayout * thisHLayout = new QHBoxLayout();
 | 
|---|
 | 37 |   QVBoxLayout * thisV1Layout = new QVBoxLayout();
 | 
|---|
 | 38 |   QVBoxLayout * thisV2Layout = new QVBoxLayout();
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |   QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
 | 
|---|
 | 41 |   QLabel *inputLabel = new QLabel("Enter to add");
 | 
|---|
 | 42 |   QListWidget* inputList = new QListWidget();
 | 
|---|
 | 43 |   inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
 | 
|---|
 | 44 |   QLineEdit* inputBox = new QLineEdit();
 | 
|---|
 | 45 |   inputLabel->setBuddy(inputBox);
 | 
|---|
 | 46 |   titleLabel->setBuddy(inputList);
 | 
|---|
 | 47 |   QPushButton* AddButton = new QPushButton("Add");
 | 
|---|
 | 48 |   AddButton->setEnabled(false);
 | 
|---|
 | 49 |   QPushButton* RemoveButton = new QPushButton("Remove");
 | 
|---|
 | 50 |   RemoveButton->setEnabled(false);
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |   thisV1Layout->addWidget(titleLabel);
 | 
|---|
 | 53 |   thisV1Layout->addWidget(inputList);
 | 
|---|
 | 54 |   thisV2Layout->addWidget(inputLabel);
 | 
|---|
 | 55 |   thisV2Layout->addWidget(inputBox);
 | 
|---|
 | 56 |   thisV2Layout->addWidget(AddButton);
 | 
|---|
 | 57 |   thisV2Layout->addWidget(RemoveButton);
 | 
|---|
 | 58 |   parent->addLayout(thisHLayout);
 | 
|---|
 | 59 |   thisHLayout->addLayout(thisV1Layout);
 | 
|---|
 | 60 |   thisHLayout->addLayout(thisV2Layout);
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 |   pipe = new QtQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
 | 
|---|
 | 63 |   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
 | 
|---|
 | 64 |   connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
 | 
|---|
 | 65 |   connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
 | 
|---|
 | 66 |   connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | QtDialog::StringsQtQuery::~StringsQtQuery()
 | 
|---|
 | 69 | {
 | 
|---|
 | 70 |   delete pipe;
 | 
|---|
 | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | // All values besides the empty std::string are valid
 | 
|---|
 | 74 | bool QtDialog::StringsQtQuery::handle()
 | 
|---|
 | 75 | {
 | 
|---|
 | 76 |   // dissect by ","
 | 
|---|
 | 77 |   std::string::iterator olditer = temp.begin();
 | 
|---|
 | 78 |   for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
 | 
|---|
 | 79 |     if (*iter == ' ') {
 | 
|---|
 | 80 |       tmp.push_back(string(iter, olditer));
 | 
|---|
 | 81 |       olditer = iter;
 | 
|---|
 | 82 |     }
 | 
|---|
 | 83 |   }
 | 
|---|
 | 84 |   if (olditer != temp.begin())  // insert last part also
 | 
|---|
 | 85 |     tmp.push_back(string(olditer, temp.end()));
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 |   return temp!="";
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|