[8df74d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * AtomsQtQueryPipe.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 25, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "UIElements/Qt4/QtDialog.hpp"
|
---|
| 21 |
|
---|
| 22 | #include <vector>
|
---|
| 23 |
|
---|
| 24 | #include <Qt/qlistwidget.h>
|
---|
| 25 |
|
---|
| 26 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
| 27 | #include "Helpers/MemDebug.hpp"
|
---|
| 28 | #include "World.hpp"
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | AtomsQtQueryPipe::AtomsQtQueryPipe(std::vector<atom *>*_content, QtDialog *_dialog, QListWidget *_theList) :
|
---|
| 32 | content(_content),
|
---|
| 33 | dialog(_dialog),
|
---|
| 34 | theList(_theList)
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
| 37 | AtomsQtQueryPipe::~AtomsQtQueryPipe()
|
---|
| 38 | {}
|
---|
| 39 |
|
---|
| 40 | void AtomsQtQueryPipe::update() {
|
---|
| 41 | // clear target and put all atoms therein
|
---|
| 42 | (*content).clear();
|
---|
| 43 | for (std::set<atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
|
---|
| 44 | (*content).push_back(*iter);
|
---|
| 45 | dialog->update();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void AtomsQtQueryPipe::add() {
|
---|
| 49 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
| 50 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
| 51 | const int index = (*iter)->text().toInt();
|
---|
| 52 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
| 53 | if (Walker) {
|
---|
| 54 | (*content).push_back(Walker);
|
---|
| 55 | currentList.insert(Walker);
|
---|
| 56 | if (lookup.find(index) != lookup.end())
|
---|
| 57 | lookup.insert(pair<int, atom*>(index, Walker));
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | update();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void AtomsQtQueryPipe::remove() {
|
---|
| 64 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
| 65 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
| 66 | const int index = (*iter)->text().toInt();
|
---|
| 67 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
| 68 | if (Walker) {
|
---|
| 69 | currentList.erase(Walker);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | update();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|