[7b8a8e] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * QtQueryList.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Jul 24, 2012
|
---|
| 12 | * Author: ankele
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | // include config.h
|
---|
| 18 | #ifdef HAVE_CONFIG_H
|
---|
| 19 | #include <config.h>
|
---|
| 20 | #endif
|
---|
| 21 |
|
---|
| 22 | #include <Qt/qboxlayout.h>
|
---|
| 23 | #include <Qt/qpushbutton.h>
|
---|
| 24 | #include <Qt/qlistwidget.h>
|
---|
| 25 |
|
---|
| 26 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 27 |
|
---|
| 28 | #include "UIElements/Qt4/Query/QtQueryList.hpp"
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | QtQueryListUntyped::QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog) :
|
---|
| 32 | dialog(_dialog)
|
---|
| 33 | {
|
---|
| 34 | thisVLayout = new QVBoxLayout();
|
---|
| 35 | thisHLayout = new QHBoxLayout();
|
---|
| 36 | buttonBox = new QVBoxLayout();
|
---|
| 37 | inputList = new QListWidget();
|
---|
| 38 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
| 39 | addButton = new QPushButton("Add");
|
---|
| 40 | addButton->setEnabled(false);
|
---|
| 41 | removeButton = new QPushButton("Remove");
|
---|
| 42 | removeButton->setEnabled(false);
|
---|
| 43 |
|
---|
| 44 | buttonBox->addWidget(addButton);
|
---|
| 45 | buttonBox->addWidget(removeButton);
|
---|
| 46 | thisHLayout->addWidget(inputList);
|
---|
| 47 | thisHLayout->addLayout(buttonBox);
|
---|
| 48 | thisVLayout->addLayout(thisHLayout);
|
---|
| 49 | parent->addLayout(thisVLayout);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | void QtQueryListUntyped::onUpdate() {
|
---|
| 55 | dialog->update();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | void QtQueryListUntyped::elementSelected()
|
---|
| 60 | {
|
---|
| 61 | removeButton->setEnabled(!inputList->selectedItems().empty());
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void QtQueryListUntyped::addElementToListWidget(const std::string &str)
|
---|
| 65 | {
|
---|
| 66 | inputList->addItem(QString(str.c_str()));
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | std::vector<int> QtQueryListUntyped::getSelectedRows()
|
---|
| 71 | {
|
---|
| 72 | std::vector<int> rows;
|
---|
| 73 | QList<QListWidgetItem*> items = inputList->selectedItems();
|
---|
| 74 | for (QList<QListWidgetItem*>::iterator iter = items.begin(); !items.empty(); iter = items.begin()){
|
---|
| 75 | rows.push_back(inputList->row(*iter));
|
---|
| 76 | items.erase(iter);
|
---|
| 77 | }
|
---|
| 78 | return rows;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void QtQueryListUntyped::removeSelectedRows(const std::vector<int> &rows)
|
---|
| 82 | {
|
---|
| 83 | for (int i = rows.size() - 1; i >= 0; i --)
|
---|
| 84 | inputList->takeItem(rows[i]);
|
---|
| 85 | }
|
---|