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 | * 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/Pipe/AtomsQtQueryPipe.hpp"
|
---|
21 | #include "UIElements/Qt4/QtDialog.hpp"
|
---|
22 |
|
---|
23 | #include <vector>
|
---|
24 |
|
---|
25 | #include <Qt/qlistwidget.h>
|
---|
26 |
|
---|
27 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
28 | #include "CodePatterns/MemDebug.hpp"
|
---|
29 | #include "World.hpp"
|
---|
30 |
|
---|
31 |
|
---|
32 | AtomsQtQueryPipe::AtomsQtQueryPipe(Parameter<std::vector<const atom *> > &_content, QtDialog *_dialog, QListWidget *_theList) :
|
---|
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 | std::vector<const atom *> temp_atoms;
|
---|
44 | for (std::set<const atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
|
---|
45 | temp_atoms.push_back(*iter);
|
---|
46 | content.set(temp_atoms);
|
---|
47 | dialog->update();
|
---|
48 | }
|
---|
49 |
|
---|
50 | void AtomsQtQueryPipe::add() {
|
---|
51 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
52 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
53 | const int index = (*iter)->text().toInt();
|
---|
54 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
55 | if (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 |
|
---|