source: src/UIElements/Views/Qt4/QtInfoBox.cpp@ 3b9aa1

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

QtInfoBox now obtains information completely from QtObservedInstanceBoard and ObservedValues.

  • Property mode set to 100644
File size: 6.3 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 "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
43
44#include "Element/element.hpp"
45#include "Element/periodentafel.hpp"
46#include "World.hpp"
47
48using namespace std;
49
50/***************** Basic structure for tab layout ***********/
51
52QtInfoBox::QtInfoBox(QtObservedInstanceBoard *_board) :
53 QTabWidget(),
54 curAtomId(-1), nextAtomId(-1),
55 curMoleculeId(-1), nextMoleculeId(-1),
56 page_mol(NULL), page_atom(NULL),
57 board(_board),
58 currentPage(0),
59 periode(World::getInstance().getPeriode())
60{
61 timer = new QTimer(this);
62 timer->setSingleShot(true);
63
64 setMinimumWidth(200);
65 setMinimumHeight(220);
66
67 connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
68}
69
70QtInfoBox::~QtInfoBox()
71{
72 clearTabs();
73}
74
75void QtInfoBox::atomHover(const atomId_t _id)
76{
77 nextAtomId = _id;
78 timer->start(500);
79}
80
81void QtInfoBox::moleculeHover(const moleculeId_t _id)
82{
83 nextMoleculeId = _id;
84 timer->start(500);
85}
86
87void QtInfoBox::timerTimeout()
88{
89 if (nextAtomId != (atomId_t)-1)
90 showAtom(nextAtomId);
91 if (nextMoleculeId != (moleculeId_t)-1)
92 showMolecule(nextMoleculeId);
93}
94
95void QtInfoBox::clearTabs()
96{
97 if (page_atom){
98 //removeTab(indexOf(page_atom));
99 delete(page_atom);
100 page_atom = NULL;
101 }
102 if (page_mol){
103 //removeTab(indexOf(page_mol));
104 delete(page_mol);
105 page_mol = NULL;
106 }
107}
108
109void QtInfoBox::showAtom(const atomId_t _id)
110{
111 currentPage = currentIndex();
112
113 // Remove old tabs.
114 clearTabs();
115
116 QtObservedAtom::ptr curAtom = board->getObservedAtom(_id);
117
118 // Show new tabs.
119 if (curAtom){
120 curAtomId = curAtom->getAtomIndex();
121 nextAtomId = -1;
122 nextMoleculeId = -1;
123
124 page_atom = new QtAtomInfoPage(curAtom, periode, this);
125 addTab(page_atom, "Atom");
126 connect(curAtom.get(), SIGNAL(atomRemoved()), this, SLOT(clearTabs()));
127
128 const moleculeId_t molid = curAtom->getAtomMoleculeIndex();
129 if (molid != (moleculeId_t)-1) {
130 QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(molid);
131 if (curMolecule) {
132 page_mol = new QtMoleculeInfoPage(curMolecule, this);
133 addTab(page_mol, "Molecule");
134 connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
135
136 if (currentPage > 0)
137 setCurrentIndex(currentPage);
138 }
139 }
140 }
141}
142
143void QtInfoBox::showMolecule(const moleculeId_t _id)
144{
145 currentPage = currentIndex();
146
147 // Remove old tabs.
148 clearTabs();
149
150 QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(_id);
151 nextAtomId = -1;
152 nextMoleculeId = -1;
153
154 // Show new tabs.
155 if (curMolecule){
156 page_mol = new QtMoleculeInfoPage(curMolecule, this);
157 addTab(page_mol, "Molecule");
158 connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearTabs()));
159
160 if (currentPage > 0)
161 setCurrentIndex(currentPage);
162 }
163}
164
165/************************ Tab for single Atoms ********************/
166
167static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
168{
169 QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
170 treeItem->setText(0, key);
171 treeItem->setText(1, value);
172}
173
174QtAtomInfoPage::QtAtomInfoPage(
175 QtObservedAtom::ptr &_atom,
176 periodentafel *_periode,
177 QWidget *parent) :
178 QTreeWidget(parent),
179 atomRef(_atom),
180 periode(_periode)
181{
182 setColumnCount(2);
183 QStringList header;
184 header << "data";
185 header << "value";
186 setHeaderLabels(header);
187
188 updatePage();
189}
190
191void QtAtomInfoPage::updatePage()
192{
193 clear();
194
195 if (atomRef == NULL)
196 return;
197 const element * const _element = periode->FindElement(atomRef->getAtomElement());
198 addInfo(this, "Name", QString(atomRef->getAtomName().c_str()));
199 addInfo(this, "Element", QString(_element->getName().c_str()));
200 addInfo(this, "Mass", QString("%1").arg(_element->getMass()));
201 addInfo(this, "Charge", QString("%1").arg(_element->getCharge()));
202 addInfo(this, "Bonds", QString("%1").arg(atomRef->getAtomBonds().size()));
203 addInfo(this, "Position x", QString(toString(atomRef->getAtomPosition()[0]).c_str()));
204 addInfo(this, "Position y", QString(toString(atomRef->getAtomPosition()[1]).c_str()));
205 addInfo(this, "Position z", QString(toString(atomRef->getAtomPosition()[2]).c_str()));
206}
207
208QtAtomInfoPage::~QtAtomInfoPage()
209{}
210
211/************************ Tab for single Molecules *****************/
212
213QtMoleculeInfoPage::QtMoleculeInfoPage(
214 QtObservedMolecule::ptr &_mol,
215 QWidget *parent) :
216 QTreeWidget(parent),
217 mol(_mol)
218{
219 setColumnCount(2);
220 QStringList header;
221 header << "data";
222 header << "value";
223 setHeaderLabels(header);
224
225 updatePage();
226}
227
228void QtMoleculeInfoPage::updatePage()
229{
230 clear();
231
232 if (mol == NULL)
233 return;
234 addInfo(this, "Name", QString(mol->getMolName().c_str()));
235 addInfo(this, "Formula", QString(mol->getMolFormula().c_str()));
236 addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
237 addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNonHydrogenCount()));
238 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
239 const Vector molCenter = mol->getMolCenter();
240 addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
241 addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
242 addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
243}
244
245QtMoleculeInfoPage::~QtMoleculeInfoPage()
246{}
Note: See TracBrowser for help on using the repository browser.