| [7b8a8e] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [94d5ac6] | 5 | * | 
|---|
|  | 6 | * | 
|---|
|  | 7 | *   This file is part of MoleCuilder. | 
|---|
|  | 8 | * | 
|---|
|  | 9 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 10 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 11 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 12 | *    (at your option) any later version. | 
|---|
|  | 13 | * | 
|---|
|  | 14 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 15 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 16 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 17 | *    GNU General Public License for more details. | 
|---|
|  | 18 | * | 
|---|
|  | 19 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 20 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| [7b8a8e] | 21 | */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /* | 
|---|
|  | 24 | * QtQueryList.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Jul 24, 2012 | 
|---|
|  | 27 | *      Author: ankele | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | // include config.h | 
|---|
|  | 33 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 34 | #include <config.h> | 
|---|
|  | 35 | #endif | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include <Qt/qboxlayout.h> | 
|---|
|  | 38 | #include <Qt/qpushbutton.h> | 
|---|
|  | 39 | #include <Qt/qlistwidget.h> | 
|---|
|  | 40 |  | 
|---|
| [9eb71b3] | 41 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| [7b8a8e] | 42 |  | 
|---|
|  | 43 | #include "UIElements/Qt4/Query/QtQueryList.hpp" | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 | QtQueryListUntyped::QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog) : | 
|---|
|  | 47 | dialog(_dialog) | 
|---|
|  | 48 | { | 
|---|
|  | 49 | thisVLayout = new QVBoxLayout(); | 
|---|
|  | 50 | thisHLayout = new QHBoxLayout(); | 
|---|
|  | 51 | buttonBox = new QVBoxLayout(); | 
|---|
|  | 52 | inputList = new QListWidget(); | 
|---|
|  | 53 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection); | 
|---|
|  | 54 | addButton = new QPushButton("Add"); | 
|---|
|  | 55 | addButton->setEnabled(false); | 
|---|
|  | 56 | removeButton = new QPushButton("Remove"); | 
|---|
|  | 57 | removeButton->setEnabled(false); | 
|---|
|  | 58 |  | 
|---|
|  | 59 | buttonBox->addWidget(addButton); | 
|---|
|  | 60 | buttonBox->addWidget(removeButton); | 
|---|
|  | 61 | thisHLayout->addWidget(inputList); | 
|---|
|  | 62 | thisHLayout->addLayout(buttonBox); | 
|---|
|  | 63 | thisVLayout->addLayout(thisHLayout); | 
|---|
|  | 64 | parent->addLayout(thisVLayout); | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 |  | 
|---|
|  | 68 |  | 
|---|
|  | 69 | void QtQueryListUntyped::onUpdate() { | 
|---|
|  | 70 | dialog->update(); | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 |  | 
|---|
|  | 74 | void QtQueryListUntyped::elementSelected() | 
|---|
|  | 75 | { | 
|---|
|  | 76 | removeButton->setEnabled(!inputList->selectedItems().empty()); | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | void QtQueryListUntyped::addElementToListWidget(const std::string &str) | 
|---|
|  | 80 | { | 
|---|
|  | 81 | inputList->addItem(QString(str.c_str())); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 |  | 
|---|
|  | 85 | std::vector<int> QtQueryListUntyped::getSelectedRows() | 
|---|
|  | 86 | { | 
|---|
|  | 87 | std::vector<int> rows; | 
|---|
|  | 88 | QList<QListWidgetItem*> items = inputList->selectedItems(); | 
|---|
|  | 89 | for (QList<QListWidgetItem*>::iterator iter = items.begin(); !items.empty(); iter = items.begin()){ | 
|---|
|  | 90 | rows.push_back(inputList->row(*iter)); | 
|---|
|  | 91 | items.erase(iter); | 
|---|
|  | 92 | } | 
|---|
|  | 93 | return rows; | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | void QtQueryListUntyped::removeSelectedRows(const std::vector<int> &rows) | 
|---|
|  | 97 | { | 
|---|
|  | 98 | for (int i = rows.size() - 1; i >= 0; i --) | 
|---|
|  | 99 | inputList->takeItem(rows[i]); | 
|---|
|  | 100 | } | 
|---|