source: src/UIElements/Views/Qt4/QtInfoBox.cpp@ 9bdbc7

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 9bdbc7 was 50246c, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: made disconnect() check for NULL pointers.

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