source: src/UIElements/Views/Qt4/QtInfoBox.cpp@ 7c7c4a

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 7c7c4a was 4965922, checked in by Frederik Heber <heber@…>, 9 years ago

QtInfoBox updates information on update signal.

  • Property mode set to 100644
File size: 6.4 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 * QtInfoBox.cpp
25 *
26 * Created on: Mar 4, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/QtInfoBox.hpp"
36
37#include <iostream>
38#include <QAbstractItemView>
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include "Descriptors/AtomIdDescriptor.hpp"
43#include "Descriptors/MoleculeIdDescriptor.hpp"
44
45#include "molecule.hpp"
46#include "Element/element.hpp"
47#include "World.hpp"
48
49using namespace std;
50
51/***************** Basic structure for tab layout ***********/
52
53QtInfoBox::QtInfoBox() :
54 QTabWidget(),
55 curAtomId(-1), nextAtomId(-1),
56 curMoleculeId(-1), nextMoleculeId(-1),
57 page_mol(NULL), page_atom(NULL)
58{
59 timer = new QTimer(this);
60 timer->setSingleShot(true);
61
62 setMinimumWidth(200);
63 setMinimumHeight(220);
64 currentPage = 0;
65
66 connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
67}
68
69QtInfoBox::~QtInfoBox()
70{
71 clearTabs();
72}
73
74void QtInfoBox::atomHover(const atomId_t _id)
75{
76 nextAtomId = _id;
77 timer->start(500);
78}
79
80void QtInfoBox::moleculeHover(const moleculeId_t _id)
81{
82 nextMoleculeId = _id;
83 timer->start(500);
84}
85
86void QtInfoBox::timerTimeout()
87{
88 if (nextAtomId != (atomId_t)-1)
89 showAtom(nextAtomId);
90 if (nextMoleculeId != (moleculeId_t)-1)
91 showMolecule(nextMoleculeId);
92}
93
94void QtInfoBox::clearTabs()
95{
96 if (page_atom){
97 //removeTab(indexOf(page_atom));
98 delete(page_atom);
99 page_atom = NULL;
100 }
101 if (page_mol){
102 //removeTab(indexOf(page_mol));
103 delete(page_mol);
104 page_mol = NULL;
105 }
106}
107
108void QtInfoBox::showAtom(const atomId_t _id)
109{
110 currentPage = currentIndex();
111
112 // Remove old tabs.
113 clearTabs();
114
115 const atom *curAtom = const_cast<const World &>(World::getInstance()).
116 getAtom(AtomById(_id));
117 curAtomId = curAtom->getId();
118 nextAtomId = -1;
119 nextMoleculeId = -1;
120
121 // Show new tabs.
122 if (curAtom){
123 page_atom = new QtAtomInfoPage(curAtom, this);
124 addTab(page_atom, "Atom");
125 connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
126
127 if (curAtom->getMolecule()){
128 page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
129 addTab(page_mol, "Molecule");
130 connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
131
132 if (currentPage > 0)
133 setCurrentIndex(currentPage);
134 }
135 }
136}
137
138void QtInfoBox::showMolecule(const moleculeId_t _id)
139{
140 currentPage = currentIndex();
141
142 // Remove old tabs.
143 clearTabs();
144
145 const molecule *curMolecule = const_cast<const World &>(World::getInstance()).
146 getMolecule(MoleculeById(_id));
147 nextAtomId = -1;
148 nextMoleculeId = -1;
149
150 // Show new tabs.
151 if (curMolecule){
152 page_mol = new QtMoleculeInfoPage(curMolecule, this);
153 addTab(page_mol, "Molecule");
154 connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
155
156 if (currentPage > 0)
157 setCurrentIndex(currentPage);
158 }
159}
160
161/************************ Tab for single Atoms ********************/
162
163static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
164{
165 QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
166 treeItem->setText(0, key);
167 treeItem->setText(1, value);
168}
169
170QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
171 QTreeWidget(parent),
172 Observer("QTAtomPage"),
173 atomRef(_atom)
174{
175 atomRef->signOn(this);
176
177 setColumnCount(2);
178 QStringList header;
179 header << "data";
180 header << "value";
181 setHeaderLabels(header);
182
183 updatePage();
184}
185
186void QtAtomInfoPage::updatePage()
187{
188 clear();
189
190 addInfo(this, "Name", QString(atomRef->getName().c_str()));
191 addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
192 addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
193 addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
194 addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
195 addInfo(this, "Position x", QString(toString(atomRef->getPosition()[0]).c_str()));
196 addInfo(this, "Position y", QString(toString(atomRef->getPosition()[1]).c_str()));
197 addInfo(this, "Position z", QString(toString(atomRef->getPosition()[2]).c_str()));
198}
199
200QtAtomInfoPage::~QtAtomInfoPage()
201{
202 if (atomRef)
203 atomRef->signOff(this);
204}
205
206void QtAtomInfoPage::update(Observable *subject)
207{
208 if (dynamic_cast<atom *>(subject) == atomRef)
209 updatePage();
210}
211
212void QtAtomInfoPage::subjectKilled(Observable *subject){
213 atomRef = NULL;
214 emit atomKilled();
215}
216
217/************************ Tab for single Molecules *****************/
218
219QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
220 QTreeWidget(parent),
221 Observer("QTMoleculePage"),
222 mol(_mol)
223{
224 mol->signOn(this);
225
226 setColumnCount(2);
227 QStringList header;
228 header << "data";
229 header << "value";
230 setHeaderLabels(header);
231
232 updatePage();
233}
234
235void QtMoleculeInfoPage::updatePage()
236{
237 clear();
238
239 addInfo(this, "Name", QString(mol->getName().c_str()));
240 addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
241 addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
242 addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNoNonHydrogen()));
243 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
244 const Vector molCenter = mol->DetermineCenterOfAll();
245 addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
246 addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
247 addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
248}
249
250QtMoleculeInfoPage::~QtMoleculeInfoPage(){
251 if (mol)
252 mol->signOff(this);
253}
254
255void QtMoleculeInfoPage::update(Observable *subject){
256 if (dynamic_cast<molecule *>(subject) == mol)
257 updatePage();
258}
259
260void QtMoleculeInfoPage::subjectKilled(Observable *subject){
261 mol = NULL;
262 emit moleculeKilled();
263}
Note: See TracBrowser for help on using the repository browser.