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

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 eb0d77 was 52575c, checked in by Frederik Heber <heber@…>, 12 years ago

QtInfoBox: save current tab page when switching atoms

  • Property mode set to 100644
File size: 4.1 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * QtInfoBox.cpp
10 *
11 * Created on: Mar 4, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Views/Qt4/QtInfoBox.hpp"
21
22#include <iostream>
23#include <QAbstractItemView>
24
25#include "CodePatterns/MemDebug.hpp"
26
27#include "molecule.hpp"
28#include "Element/element.hpp"
29
30using namespace std;
31
32/***************** Basic structure for tab layout ***********/
33
34QtInfoBox::QtInfoBox() :
35 QTabWidget(),
36 curAtom(NULL), nextAtom(NULL),
37 page_mol(NULL), page_atom(NULL)
38{
39 timer = new QTimer(this);
40 timer->setSingleShot(true);
41
42 setMinimumWidth(200);
43 currentPage = 0;
44
45 connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
46}
47
48QtInfoBox::~QtInfoBox()
49{
50 clearTabs();
51}
52
53void QtInfoBox::atomHover(const atom *_atom)
54{
55 nextAtom = _atom;
56 timer->start(500);
57}
58
59void QtInfoBox::timerTimeout()
60{
61 if (nextAtom)
62 showAtom(nextAtom);
63}
64
65void QtInfoBox::clearTabs()
66{
67 if (page_atom){
68 //removeTab(indexOf(page_atom));
69 delete(page_atom);
70 page_atom = NULL;
71 }
72 if (page_mol){
73 //removeTab(indexOf(page_mol));
74 delete(page_mol);
75 page_mol = NULL;
76 }
77}
78
79void QtInfoBox::showAtom(const atom *_atom)
80{
81 currentPage = currentIndex();
82
83 // Remove old tabs.
84 clearTabs();
85
86 curAtom = _atom;
87
88 // Show new tabs.
89 if (curAtom){
90 page_atom = new QtAtomInfoPage(curAtom, this);
91 addTab(page_atom, "Atom");
92 connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
93
94 if (curAtom->getMolecule()){
95 page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
96 addTab(page_mol, "Molecule");
97 connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
98
99 if (currentPage > 0)
100 setCurrentIndex(currentPage);
101 }
102 }
103}
104
105/************************ Tab for single Atoms ********************/
106
107static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
108{
109 QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
110 treeItem->setText(0, key);
111 treeItem->setText(1, value);
112}
113
114QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
115 QTreeWidget(parent),
116 Observer("QTAtomPage"),
117 atomRef(_atom)
118{
119 atomRef->signOn(this);
120
121 setColumnCount(2);
122 QStringList header;
123 header << "data";
124 header << "value";
125 setHeaderLabels(header);
126
127 addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
128 addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
129 addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
130 addInfo(this, "Position", QString(toString(atomRef->getPosition()).c_str()));
131 addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
132}
133
134QtAtomInfoPage::~QtAtomInfoPage()
135{
136 if (atomRef)
137 atomRef->signOff(this);
138}
139
140void QtAtomInfoPage::update(Observable *subject){
141 /*if(name != atomRef->name){
142 name = atomRef->name;
143 emit nameChanged(this,name);
144 }*/
145}
146
147void QtAtomInfoPage::subjectKilled(Observable *subject){
148 atomRef = NULL;
149 emit atomKilled();
150}
151
152/************************ Tab for single Molecules *****************/
153
154QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
155 QTreeWidget(parent),
156 Observer("QTMoleculePage"),
157 mol(_mol)
158{
159 mol->signOn(this);
160
161 setColumnCount(2);
162 QStringList header;
163 header << "data";
164 header << "value";
165 setHeaderLabels(header);
166
167 addInfo(this, "Name", QString(mol->getName().c_str()));
168 addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
169 addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
170 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
171}
172
173QtMoleculeInfoPage::~QtMoleculeInfoPage(){
174 if (mol)
175 mol->signOff(this);
176}
177
178void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
179}
180
181void QtMoleculeInfoPage::subjectKilled(Observable *subject){
182 mol = NULL;
183 emit moleculeKilled();
184}
Note: See TracBrowser for help on using the repository browser.