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

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 d1831e 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
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[bcf653]21 */
22
[b47bfc]23/*
[3c53fa]24 * QtInfoBox.cpp
[b47bfc]25 *
26 * Created on: Mar 4, 2010
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
[bbbad5]34
[3c53fa]35#include "Views/Qt4/QtInfoBox.hpp"
[b47bfc]36
37#include <iostream>
[4f7473]38#include <QAbstractItemView>
[b47bfc]39
[ad011c]40#include "CodePatterns/MemDebug.hpp"
[bbbad5]41
[e7341e]42#include "Descriptors/AtomIdDescriptor.hpp"
43#include "Descriptors/MoleculeIdDescriptor.hpp"
44
[bbbad5]45#include "molecule.hpp"
[4f7473]46#include "Element/element.hpp"
[e7341e]47#include "World.hpp"
[b47bfc]48
49using namespace std;
50
51/***************** Basic structure for tab layout ***********/
52
[3c53fa]53QtInfoBox::QtInfoBox() :
[7b6bcfe]54 QTabWidget(),
[e7341e]55 curAtomId(-1), nextAtomId(-1),
56 curMoleculeId(-1), nextMoleculeId(-1),
[7b6bcfe]57 page_mol(NULL), page_atom(NULL)
[b47bfc]58{
[4a2f3e]59 timer = new QTimer(this);
60 timer->setSingleShot(true);
[b47bfc]61
[0b2be1]62 setMinimumWidth(200);
[5dcb3c]63 setMinimumHeight(220);
[52575c]64 currentPage = 0;
[0b2be1]65
[4a2f3e]66 connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
[b47bfc]67}
68
[3c53fa]69QtInfoBox::~QtInfoBox()
[be374a]70{
71 clearTabs();
72}
[b47bfc]73
[e7341e]74void QtInfoBox::atomHover(const atomId_t _id)
[4a2f3e]75{
[e7341e]76 nextAtomId = _id;
[2b596f]77 timer->start(500);
78}
79
[e7341e]80void QtInfoBox::moleculeHover(const moleculeId_t _id)
[2b596f]81{
[e7341e]82 nextMoleculeId = _id;
[4a2f3e]83 timer->start(500);
[b47bfc]84}
85
[3c53fa]86void QtInfoBox::timerTimeout()
[4a2f3e]87{
[e7341e]88 if (nextAtomId != (atomId_t)-1)
89 showAtom(nextAtomId);
90 if (nextMoleculeId != (moleculeId_t)-1)
91 showMolecule(nextMoleculeId);
[b47bfc]92}
93
[3c53fa]94void QtInfoBox::clearTabs()
[7b6bcfe]95{
96 if (page_atom){
[be374a]97 //removeTab(indexOf(page_atom));
[7b6bcfe]98 delete(page_atom);
99 page_atom = NULL;
100 }
101 if (page_mol){
[be374a]102 //removeTab(indexOf(page_mol));
[7b6bcfe]103 delete(page_mol);
104 page_mol = NULL;
105 }
[be374a]106}
[7b6bcfe]107
[e7341e]108void QtInfoBox::showAtom(const atomId_t _id)
[be374a]109{
[52575c]110 currentPage = currentIndex();
111
[be374a]112 // Remove old tabs.
113 clearTabs();
114
[e7341e]115 const atom *curAtom = const_cast<const World &>(World::getInstance()).
116 getAtom(AtomById(_id));
117 curAtomId = curAtom->getId();
118 nextAtomId = -1;
119 nextMoleculeId = -1;
[7b6bcfe]120
121 // Show new tabs.
[4a2f3e]122 if (curAtom){
[0b2be1]123 page_atom = new QtAtomInfoPage(curAtom, this);
[4f7473]124 addTab(page_atom, "Atom");
[be374a]125 connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
[4f7473]126
[7772aa]127 if (curAtom->getMolecule()){
[0b2be1]128 page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
[7772aa]129 addTab(page_mol, "Molecule");
[be374a]130 connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
[52575c]131
132 if (currentPage > 0)
133 setCurrentIndex(currentPage);
[7772aa]134 }
[7b6bcfe]135 }
136}
137
[e7341e]138void QtInfoBox::showMolecule(const moleculeId_t _id)
[2b596f]139{
140 currentPage = currentIndex();
141
142 // Remove old tabs.
143 clearTabs();
144
[e7341e]145 const molecule *curMolecule = const_cast<const World &>(World::getInstance()).
146 getMolecule(MoleculeById(_id));
147 nextAtomId = -1;
148 nextMoleculeId = -1;
[2b596f]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
[7b6bcfe]161/************************ Tab for single Atoms ********************/
[b47bfc]162
[4f7473]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
[0b2be1]170QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
171 QTreeWidget(parent),
[7b6bcfe]172 Observer("QTAtomPage"),
[4f7473]173 atomRef(_atom)
[7b6bcfe]174{
175 atomRef->signOn(this);
[4f7473]176
[0b2be1]177 setColumnCount(2);
[4f7473]178 QStringList header;
179 header << "data";
180 header << "value";
[0b2be1]181 setHeaderLabels(header);
[4f7473]182
[4965922]183 updatePage();
184}
185
186void QtAtomInfoPage::updatePage()
187{
188 clear();
189
[5e4bfd]190 addInfo(this, "Name", QString(atomRef->getName().c_str()));
[0b2be1]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()));
[5dcb3c]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()));
[7b6bcfe]198}
[b47bfc]199
[3c53fa]200QtAtomInfoPage::~QtAtomInfoPage()
[7b6bcfe]201{
[be374a]202 if (atomRef)
203 atomRef->signOff(this);
[7b6bcfe]204}
[b47bfc]205
[4965922]206void QtAtomInfoPage::update(Observable *subject)
207{
208 if (dynamic_cast<atom *>(subject) == atomRef)
209 updatePage();
[7b6bcfe]210}
[b47bfc]211
[3c53fa]212void QtAtomInfoPage::subjectKilled(Observable *subject){
[be374a]213 atomRef = NULL;
214 emit atomKilled();
215}
[b47bfc]216
217/************************ Tab for single Molecules *****************/
218
[0b2be1]219QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
220 QTreeWidget(parent),
[b47bfc]221 Observer("QTMoleculePage"),
[4f7473]222 mol(_mol)
[b47bfc]223{
224 mol->signOn(this);
[4f7473]225
[0b2be1]226 setColumnCount(2);
[4f7473]227 QStringList header;
228 header << "data";
229 header << "value";
[0b2be1]230 setHeaderLabels(header);
[4f7473]231
[4965922]232 updatePage();
233}
234
235void QtMoleculeInfoPage::updatePage()
236{
237 clear();
238
[0b2be1]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()));
[5dcb3c]242 addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNoNonHydrogen()));
[0b2be1]243 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
[5dcb3c]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]));
[b47bfc]248}
249
[3c53fa]250QtMoleculeInfoPage::~QtMoleculeInfoPage(){
[be374a]251 if (mol)
252 mol->signOff(this);
[b47bfc]253}
254
[4965922]255void QtMoleculeInfoPage::update(Observable *subject){
256 if (dynamic_cast<molecule *>(subject) == mol)
257 updatePage();
[b47bfc]258}
259
[3c53fa]260void QtMoleculeInfoPage::subjectKilled(Observable *subject){
[be374a]261 mol = NULL;
262 emit moleculeKilled();
263}
Note: See TracBrowser for help on using the repository browser.