source: src/UIElements/Views/Qt4/ElementList/QtElementList.cpp@ 1e1893

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 1e1893 was 1e1893, checked in by Frederik Heber <heber@…>, 9 years ago

Moved QtElementList into own subfolder.

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
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/>.
21 */
22
23/*
24 * QtElementList.cpp
25 *
26 * Created on: Mar 6, 2012
27 * Author: ankele
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/ElementList/QtElementList.hpp"
36#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
37
38#include <iostream>
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include "Atom/atom.hpp"
43#include "Atom/AtomObserver.hpp"
44
45#include "Element/element.hpp"
46#include "Element/periodentafel.hpp"
47#include "Descriptors/AtomTypeDescriptor.hpp"
48#include <QAbstractItemView>
49#include "Actions/SelectionAction/Atoms/AtomByElementAction.hpp"
50#include "Actions/SelectionAction/Atoms/NotAtomByElementAction.hpp"
51
52using namespace std;
53
54const int QtElementList::COLUMNCOUNT = COLUMNTYPES_MAX;
55const char *QtElementList::COLUMNNAMES[QtElementList::COLUMNCOUNT]={"Number","Name","Symbol","Mass","Occurrence"};
56
57QtElementList::QtElementList(QtObservedInstanceBoard *_board, QWidget * _parent) :
58 QTreeWidget (_parent),
59 Observer("QtElementList"),
60 board(_board)
61{
62 setColumnCount(COLUMNCOUNT);
63 setSelectionMode(QAbstractItemView::MultiSelection);
64
65 QStringList header;
66 for(int i=0; i<COLUMNCOUNT;++i)
67 header << COLUMNNAMES[i];
68 setHeaderLabels(header);
69
70 {
71 periodentafel *&periode = World::getInstance().getPeriode();
72
73 elementSelection.clear();
74
75 int i;
76
77 clear();
78 periodentafel::const_iterator iter;
79 for(iter = periode->begin(),i=0;
80 iter != periode->end();
81 ++i,++iter) {
82 const element *e = iter->second;
83 int count = 0;
84 count = const_cast<const World &>(World::getInstance()).
85 getAllAtoms(AtomByType(e)).size();
86
87 QTreeWidgetItem *treeItem = new QTreeWidgetItem(this);
88 treeItem->setText(NUMBER, QString::number(e->getAtomicNumber()));
89 treeItem->setText(NAME, QString(e->getName().c_str()));
90 treeItem->setText(SYMBOL, QString(e->getSymbol().c_str()));
91 treeItem->setText(MASS, QString::number(e->getMass()));
92 setOccurrence(*treeItem, count);
93 elementSelection.push_back(treeItem->isSelected());
94// insertTopLevelItem(e->getAtomicNumber()-1, treeItem);
95 }
96 }
97 dirty = true;
98
99 AtomObserver::getInstance().signOn(this, atom::ElementChanged);
100
101 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
102 connect(this,SIGNAL(needsRefill(const atomId_t)),this,SLOT(refill(const atomId_t)), Qt::QueuedConnection);
103// connect(this,SIGNAL(changed()),this,SLOT(update()));
104
105}
106
107QtElementList::~QtElementList()
108{
109 AtomObserver::getInstance().signOff(this, atom::ElementChanged);
110}
111
112void QtElementList::update(Observable *publisher)
113{
114 ASSERT(0, "QtElementList::update() - is not enlisted to any general update.");
115}
116
117
118void QtElementList::recieveNotification(Observable *publisher, Notification_ptr notification)
119{
120 if (notification->getChannelNo() == atom::ElementChanged) {
121 dirty = true;
122
123 emit needsRefill(dynamic_cast<atom *>(publisher)->getId());
124 } else
125 ASSERT(0, "QtElementList::recieveNotification() - we are not enlisted to any other instance's channel.");
126}
127
128void QtElementList::updateElement(const QtObservedAtom::ptr &_atom)
129{
130 const atomicNumber_t newelement = _atom->getAtomElement();
131 atomicNumber_t oldelement = -1;
132 const atomId_t atomid = _atom->getAtomIndex();
133 QTreeWidgetItem *newtreeItem = topLevelItem(newelement-1);
134 ASSERT( newtreeItem != NULL,
135 "QtElementList::updateElement() - new element item not present.");
136// if (newtreeItem == NULL) {
137// // add new item
138// const element& e = _atom.getElement();
139// newtreeItem = new QTreeWidgetItem();
140// newtreeItem->setText(NUMBER, QString::number(e.getAtomicNumber()));
141// newtreeItem->setText(NAME, QString(e.getName().c_str()));
142// newtreeItem->setText(SYMBOL, QString(e.getSymbol().c_str()));
143// newtreeItem->setText(MASS, QString::number(e.getMass()));
144// setOccurrence(*newtreeItem, 0);
145// elementSelection.push_back(newtreeItem->isSelected());
146// insertTopLevelItem(newelement-1, newtreeItem);
147// }
148 AtomElementMap_t::iterator iter = AtomElementMap.find(atomid);
149 if (iter == AtomElementMap.end()) {
150 AtomElementMap.insert( std::make_pair(atomid, -1));
151 iter = AtomElementMap.find(atomid);
152 } else
153 oldelement = iter->second;
154 iter->second = newelement;
155
156 // reduce old occurence
157 if (oldelement != (atomicNumber_t)-1) {
158 QTreeWidgetItem *oldtreeItem = topLevelItem(oldelement-1);
159 ASSERT( oldtreeItem != NULL,
160 "QtElementList::updateElement() - old element item not present.");
161 const int count_old = oldtreeItem->text(OCCURRENCE).toInt();
162 setOccurrence(*oldtreeItem, count_old-1);
163 }
164 // increase new occurence
165 const int count_new = newtreeItem->text(OCCURRENCE).toInt();
166 setOccurrence(*newtreeItem, count_new+1);
167}
168
169void QtElementList::setOccurrence(QTreeWidgetItem &_item, const int count)
170{
171 ASSERT (count >= 0,
172 "QtElementList::setOccurrence() - count for an elment < 0.");
173
174 if (count > 0) {
175 _item.setText(OCCURRENCE, QString::number(count));
176 if (_item.isDisabled())
177 _item.setDisabled(false);
178 } else {
179 _item.setText(OCCURRENCE, "none");
180 _item.setDisabled(true);
181 }
182}
183
184void QtElementList::refill(const atomId_t _atomid)
185{
186 refill_mutex.lock();
187
188 const QtObservedAtom::ptr walker = board->getObservedAtom(_atomid);
189 if (walker)
190 updateElement(walker);
191 else {
192 AtomElementMap_t::iterator iter = AtomElementMap.find(_atomid);
193 if (iter != AtomElementMap.end()) {
194 QTreeWidgetItem *oldtreeItem = topLevelItem(iter->second-1);
195 const int count_old = oldtreeItem->text(OCCURRENCE).toInt();
196 setOccurrence(*oldtreeItem, count_old-1);
197
198 AtomElementMap.erase(iter);
199 }
200 }
201
202 refill_mutex.unlock();
203}
204
205void QtElementList::paintEvent(QPaintEvent * event)
206{
207// if (dirty)
208// refill();
209 QTreeWidget::paintEvent(event);
210}
211
212void QtElementList::subjectKilled(Observable *publisher) {
213}
214
215
216void QtElementList::rowSelected()
217{
218 //std::cout << "rowSelected\n";
219 periodentafel *&periode = World::getInstance().getPeriode();
220
221 for (int i=0;i<topLevelItemCount();i++){
222 QTreeWidgetItem *item = topLevelItem(i);
223 bool newSelection = item->isSelected();
224 if (newSelection != elementSelection[i]){
225 elementSelection[i] = newSelection;
226
227 int atomicNumber = item->text(NUMBER).toInt();
228 const element *e = periode->FindElement(atomicNumber);
229 if (newSelection)
230 MoleCuilder::SelectionAtomByElement(e);
231 else
232 MoleCuilder::SelectionNotAtomByElement(e);
233 }
234 }
235}
236
Note: See TracBrowser for help on using the repository browser.