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