source: src/UIElements/Views/Qt4/QtInfoBox.cpp@ e7341e

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

FIX: QtInfoBox now works mostly on ids.

  • slots are requested as ..Id_t and not as ptrs anymore for some time.
  • 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 "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 addInfo(this, "Name", QString(atomRef->getName().c_str()));
184 addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
185 addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
186 addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
187 addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
188 addInfo(this, "Position x", QString(toString(atomRef->getPosition()[0]).c_str()));
189 addInfo(this, "Position y", QString(toString(atomRef->getPosition()[1]).c_str()));
190 addInfo(this, "Position z", QString(toString(atomRef->getPosition()[2]).c_str()));
191}
192
193QtAtomInfoPage::~QtAtomInfoPage()
194{
195 if (atomRef)
196 atomRef->signOff(this);
197}
198
199void QtAtomInfoPage::update(Observable *subject){
200 /*if(name != atomRef->name){
201 name = atomRef->name;
202 emit nameChanged(this,name);
203 }*/
204}
205
206void QtAtomInfoPage::subjectKilled(Observable *subject){
207 atomRef = NULL;
208 emit atomKilled();
209}
210
211/************************ Tab for single Molecules *****************/
212
213QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
214 QTreeWidget(parent),
215 Observer("QTMoleculePage"),
216 mol(_mol)
217{
218 mol->signOn(this);
219
220 setColumnCount(2);
221 QStringList header;
222 header << "data";
223 header << "value";
224 setHeaderLabels(header);
225
226 addInfo(this, "Name", QString(mol->getName().c_str()));
227 addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
228 addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
229 addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNoNonHydrogen()));
230 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
231 const Vector molCenter = mol->DetermineCenterOfAll();
232 addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
233 addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
234 addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
235}
236
237QtMoleculeInfoPage::~QtMoleculeInfoPage(){
238 if (mol)
239 mol->signOff(this);
240}
241
242void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
243}
244
245void QtMoleculeInfoPage::subjectKilled(Observable *subject){
246 mol = NULL;
247 emit moleculeKilled();
248}
Note: See TracBrowser for help on using the repository browser.