/* * QtQueryListPipe.hpp * * Created on: Oct 25, 2010 * Author: heber */ #ifndef QTQUERYLISTPIPE_HPP_ #define QTQUERYLISTPIPE_HPP_ #include "QtQueryPipe.hpp" #include using boost::lexical_cast; using boost::bad_lexical_cast; template QtQueryListPipe::QtQueryListPipe(std::vector *_content, QtDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) : content(_content), dialog(_dialog), inputBox(_inputBox), inputList(_inputList), AddButton(_AddButton), RemoveButton(_RemoveButton) {} template QtQueryListPipe::~QtQueryListPipe() {} template void QtQueryListPipe::IntegerEntered(const QString&) { AddButton->setEnabled(true); } template void QtQueryListPipe::IntegerSelected() { if (inputList->selectedItems().empty()) RemoveButton->setEnabled(false); else RemoveButton->setEnabled(true); } template void QtQueryListPipe::AddInteger() { // type-check std::string text = inputBox->text().toStdString(); int number = 0; try { number = boost::lexical_cast(text); } catch (boost::bad_lexical_cast&) { return; }; // add item to both inputList->addItem(QString(number)); AddValue(number); } template void QtQueryListPipe::AddValue(T item) { content->push_back(item); dialog->update(); } template void QtQueryListPipe::RemoveInteger() { QList items = inputList->selectedItems(); for (QList::iterator iter = items.begin(); !items.empty(); iter = items.begin()) { // obtain which position item has (by making it current item) inputList->setCurrentItem(*iter); // remove QtQueryListPipe::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call inputList->removeItemWidget(*iter); } } template void QtQueryListPipe::RemoveRow(int row) { int counter = 0; typename std::vector::iterator iter = content->begin(); for (; iter != content->end(); ++iter) if (counter++ == row) break; if (iter != content->end()) content->erase(iter); } #endif /* QTQUERYLISTPIPE_HPP_ */