[8df74d] | 1 | /*
|
---|
| 2 | * QtQueryListPipe.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Oct 25, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef QTQUERYLISTPIPE_HPP_
|
---|
| 9 | #define QTQUERYLISTPIPE_HPP_
|
---|
| 10 |
|
---|
[56f73b] | 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 |
|
---|
[f10b0c] | 17 | #include "Parameters/Parameter.hpp"
|
---|
[a5ddf0] | 18 | #include "QtQueryPipe.hpp"
|
---|
| 19 |
|
---|
[5813ac] | 20 | #include <boost/lexical_cast.hpp>
|
---|
| 21 |
|
---|
| 22 | using boost::lexical_cast;
|
---|
| 23 | using boost::bad_lexical_cast;
|
---|
| 24 |
|
---|
[a5ddf0] | 25 |
|
---|
[f10b0c] | 26 | template<typename T> QtQueryListPipe<T>::QtQueryListPipe(Parameter<std::vector<T> > &_content, QtDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
|
---|
[8df74d] | 27 | content(_content),
|
---|
| 28 | dialog(_dialog),
|
---|
| 29 | inputBox(_inputBox),
|
---|
| 30 | inputList(_inputList),
|
---|
| 31 | AddButton(_AddButton),
|
---|
| 32 | RemoveButton(_RemoveButton)
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | template<typename T> QtQueryListPipe<T>::~QtQueryListPipe()
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
| 38 | template<typename T> void QtQueryListPipe<T>::IntegerEntered(const QString&)
|
---|
| 39 | {
|
---|
| 40 | AddButton->setEnabled(true);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | template<typename T> void QtQueryListPipe<T>::IntegerSelected()
|
---|
| 44 | {
|
---|
| 45 | if (inputList->selectedItems().empty())
|
---|
| 46 | RemoveButton->setEnabled(false);
|
---|
| 47 | else
|
---|
| 48 | RemoveButton->setEnabled(true);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | template<typename T> void QtQueryListPipe<T>::AddInteger() {
|
---|
| 52 | // type-check
|
---|
| 53 | std::string text = inputBox->text().toStdString();
|
---|
| 54 | int number = 0;
|
---|
| 55 | try {
|
---|
| 56 | number = boost::lexical_cast<int>(text);
|
---|
| 57 | } catch (boost::bad_lexical_cast&) {
|
---|
| 58 | return;
|
---|
| 59 | };
|
---|
| 60 | // add item to both
|
---|
| 61 | inputList->addItem(QString(number));
|
---|
| 62 | AddValue(number);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | template<typename T> void QtQueryListPipe<T>::AddValue(T item) {
|
---|
| 66 | content->push_back(item);
|
---|
| 67 |
|
---|
| 68 | dialog->update();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | template<typename T> void QtQueryListPipe<T>::RemoveInteger() {
|
---|
| 72 | QList<QListWidgetItem *> items = inputList->selectedItems();
|
---|
| 73 | for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
|
---|
| 74 | // obtain which position item has (by making it current item)
|
---|
| 75 | inputList->setCurrentItem(*iter);
|
---|
| 76 | // remove
|
---|
| 77 | QtQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
|
---|
| 78 | inputList->removeItemWidget(*iter);
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | template<typename T> void QtQueryListPipe<T>::RemoveRow(int row) {
|
---|
| 83 | int counter = 0;
|
---|
| 84 | typename std::vector<T>::iterator iter = content->begin();
|
---|
| 85 | for (; iter != content->end(); ++iter)
|
---|
| 86 | if (counter++ == row)
|
---|
| 87 | break;
|
---|
| 88 | if (iter != content->end())
|
---|
| 89 | content->erase(iter);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | #endif /* QTQUERYLISTPIPE_HPP_ */
|
---|