| [8df74d] | 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| [0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| [8df74d] | 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 |
|
|---|
| [a5ddf0] | 20 | #include "UIElements/Qt4/Pipe/AtomsQtQueryPipe.hpp"
|
|---|
| [8df74d] | 21 | #include "UIElements/Qt4/QtDialog.hpp"
|
|---|
| 22 |
|
|---|
| 23 | #include <vector>
|
|---|
| 24 |
|
|---|
| 25 | #include <Qt/qlistwidget.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "Descriptors/AtomIdDescriptor.hpp"
|
|---|
| [ad011c] | 28 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| [8df74d] | 29 | #include "World.hpp"
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| [e4afb4] | 32 | AtomsQtQueryPipe::AtomsQtQueryPipe(std::vector<const atom *>*_content, QtDialog *_dialog, QListWidget *_theList) :
|
|---|
| [8df74d] | 33 | content(_content),
|
|---|
| 34 | dialog(_dialog),
|
|---|
| 35 | theList(_theList)
|
|---|
| 36 | {}
|
|---|
| 37 |
|
|---|
| 38 | AtomsQtQueryPipe::~AtomsQtQueryPipe()
|
|---|
| 39 | {}
|
|---|
| 40 |
|
|---|
| 41 | void AtomsQtQueryPipe::update() {
|
|---|
| 42 | // clear target and put all atoms therein
|
|---|
| 43 | (*content).clear();
|
|---|
| [e4afb4] | 44 | for (std::set<const atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
|
|---|
| [8df74d] | 45 | (*content).push_back(*iter);
|
|---|
| 46 | dialog->update();
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void AtomsQtQueryPipe::add() {
|
|---|
| 50 | QList<QListWidgetItem *> items = theList->selectedItems();
|
|---|
| 51 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
|---|
| 52 | const int index = (*iter)->text().toInt();
|
|---|
| 53 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
|---|
| 54 | if (Walker) {
|
|---|
| 55 | (*content).push_back(Walker);
|
|---|
| 56 | currentList.insert(Walker);
|
|---|
| 57 | if (lookup.find(index) != lookup.end())
|
|---|
| 58 | lookup.insert(pair<int, atom*>(index, Walker));
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 | update();
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void AtomsQtQueryPipe::remove() {
|
|---|
| 65 | QList<QListWidgetItem *> items = theList->selectedItems();
|
|---|
| 66 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
|---|
| 67 | const int index = (*iter)->text().toInt();
|
|---|
| 68 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
|---|
| 69 | if (Walker) {
|
|---|
| 70 | currentList.erase(Walker);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 | update();
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|