| 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 |  | 
|---|
| 11 | template<typename T> QtQueryListPipe<T>::QtQueryListPipe(std::vector<T> *_content, QtDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) : | 
|---|
| 12 | content(_content), | 
|---|
| 13 | dialog(_dialog), | 
|---|
| 14 | inputBox(_inputBox), | 
|---|
| 15 | inputList(_inputList), | 
|---|
| 16 | AddButton(_AddButton), | 
|---|
| 17 | RemoveButton(_RemoveButton) | 
|---|
| 18 | {} | 
|---|
| 19 |  | 
|---|
| 20 | template<typename T> QtQueryListPipe<T>::~QtQueryListPipe() | 
|---|
| 21 | {} | 
|---|
| 22 |  | 
|---|
| 23 | template<typename T> void QtQueryListPipe<T>::IntegerEntered(const QString&) | 
|---|
| 24 | { | 
|---|
| 25 | AddButton->setEnabled(true); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | template<typename T> void QtQueryListPipe<T>::IntegerSelected() | 
|---|
| 29 | { | 
|---|
| 30 | if (inputList->selectedItems().empty()) | 
|---|
| 31 | RemoveButton->setEnabled(false); | 
|---|
| 32 | else | 
|---|
| 33 | RemoveButton->setEnabled(true); | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | template<typename T> void QtQueryListPipe<T>::AddInteger() { | 
|---|
| 37 | // type-check | 
|---|
| 38 | std::string text = inputBox->text().toStdString(); | 
|---|
| 39 | int number = 0; | 
|---|
| 40 | try { | 
|---|
| 41 | number = boost::lexical_cast<int>(text); | 
|---|
| 42 | } catch (boost::bad_lexical_cast&) { | 
|---|
| 43 | return; | 
|---|
| 44 | }; | 
|---|
| 45 | // add item to both | 
|---|
| 46 | inputList->addItem(QString(number)); | 
|---|
| 47 | AddValue(number); | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | template<typename T> void QtQueryListPipe<T>::AddValue(T item) { | 
|---|
| 51 | content->push_back(item); | 
|---|
| 52 |  | 
|---|
| 53 | dialog->update(); | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | template<typename T> void QtQueryListPipe<T>::RemoveInteger() { | 
|---|
| 57 | QList<QListWidgetItem *> items = inputList->selectedItems(); | 
|---|
| 58 | for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) { | 
|---|
| 59 | // obtain which position item has (by making it current item) | 
|---|
| 60 | inputList->setCurrentItem(*iter); | 
|---|
| 61 | // remove | 
|---|
| 62 | QtQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call | 
|---|
| 63 | inputList->removeItemWidget(*iter); | 
|---|
| 64 | } | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | template<typename T> void QtQueryListPipe<T>::RemoveRow(int row) { | 
|---|
| 68 | int counter = 0; | 
|---|
| 69 | typename std::vector<T>::iterator iter = content->begin(); | 
|---|
| 70 | for (; iter != content->end(); ++iter) | 
|---|
| 71 | if (counter++ == row) | 
|---|
| 72 | break; | 
|---|
| 73 | if (iter != content->end()) | 
|---|
| 74 | content->erase(iter); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | #endif /*  QTQUERYLISTPIPE_HPP_  */ | 
|---|