source: src/UIElements/Views/Qt4/QtWorldView.cpp@ 47812b

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

FIX: MolecuilderGUI crashes on selecting molecule.

  • QtWorldView::update() set ATOMS column twice, hence FORMULA was NULL item.
  • rename in enum COLUMNTYPES: ATOMS->ATOMCOUNT.
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * QtWorldView.cpp
10 *
11 * Created on: Jan 21, 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/QtWorldView.hpp"
21
22#include <iostream>
23
24#include "CodePatterns/MemDebug.hpp"
25
26#include "atom.hpp"
27#include "Formula.hpp"
28#include "molecule.hpp"
29
30using namespace std;
31
32// maybe this should go with the definition of molecules
33
34// some attributes need to be easier to find for molecules
35// these attributes are skiped so far
36const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
37const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula"/*,"Size"*/};
38
39QtWorldView::QtWorldView(QWidget * _parent) :
40 QTableWidget (_parent),
41 Observer("QtWorldView")
42{
43 setRowCount(0);
44 setColumnCount(COLUMNCOUNT);
45
46 for(int i=0; i<COLUMNCOUNT;++i) {
47 QTableWidgetItem *heading = new QTableWidgetItem();
48 std::cout << "Creating heading item " << heading << "." << std::endl;
49 heading->setText(QString(COLUMNNAMES[i]));
50 setHorizontalHeaderItem(i,heading);
51 }
52
53 molecules = World::getInstance().getMolecules();
54 molecules->signOn(this);
55 update(molecules);
56
57 connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
58 connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
59
60}
61
62QtWorldView::~QtWorldView()
63{
64 molecules->signOff(this);
65}
66
67void QtWorldView::update(Observable *publisher) {
68 int numMolecules = molecules->ListOfMolecules.size();
69 setRowCount(numMolecules);
70 molSelection.resize(numMolecules);
71 int i;
72 MoleculeList::iterator iter;
73 for(iter = molecules->ListOfMolecules.begin(),i=0;
74 iter != molecules->ListOfMolecules.end();
75 ++i,++iter) {
76
77 const int index = (*iter)->IndexNr;
78 QTableWidgetItem *indexWidget = new QTableWidgetItem();
79 //std::cout << "Creating index item " << indexWidget << "." << std::endl;
80 indexWidget->setText(QString::number(index));
81 indexWidget->setData(Qt::UserRole,QVariant(index));
82 setVerticalHeaderItem(i,indexWidget);
83
84 const string name = (*iter)->getName();
85 QTableWidgetItem *nameWidget = new QTableWidgetItem();
86 //std::cout << "Creating name item " << nameWidget << " at " << i << "," << NAME << "." << std::endl;
87 nameWidget->setText(QString(name.c_str()));
88 setItem(i,NAME,nameWidget);
89
90 const int atomCount = (*iter)->getAtomCount();
91 QTableWidgetItem *countWidget= new QTableWidgetItem();
92 //std::cout << "Creating count item " << countWidget << " at " << i << "," << ATOMCOUNT << "." << std::endl;
93 countWidget->setText(QString::number(atomCount));
94 countWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
95 setItem(i,ATOMCOUNT,countWidget);
96
97 const Formula formula = (*iter)->getFormula();
98 QTableWidgetItem *formulaWidget= new QTableWidgetItem();
99 //std::cout << "Creating formula item " << formulaWidget << " at " << i << "," << FORMULA << "." << std::endl;
100 formulaWidget->setText(QString(formula.toString().c_str()));
101 formulaWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
102 setItem(i,FORMULA,formulaWidget);
103
104 molSelection[i]=nameWidget->isSelected();
105 }
106}
107
108void QtWorldView::subjectKilled(Observable *publisher) {
109}
110
111void QtWorldView::moleculeChanged(int row, int column) {
112 int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
113 molecule *mol = molecules->ReturnIndex(idx);
114 string cellValue = item(row,NAME)->text().toStdString();
115 if(mol->getName() != cellValue && cellValue !="") {
116 mol->setName(cellValue);
117 }
118 else if(cellValue==""){
119 item(row,NAME)->setText(QString(mol->getName().c_str()));
120 }
121}
122
123
124void QtWorldView::cellSelected(int row, int column){
125 //std::cout << "Selection in (" << row << "," << column << "): " << item(row,column) << std::endl;
126 bool state = item(row,column)->isSelected();
127 for(int i = 0; i<COLUMNCOUNT; i++){
128 //std::cout << "Setting " << i << "-th item " << item(row,i) << " in row " << row << " to state selected." << std::endl;
129 item(row,i)->setSelected(state);
130 }
131 // figure out which rows have changed
132 for(int i=0; i<rowCount();++i){
133 state = item(i,0)->isSelected();
134 if(molSelection[i]!=state){
135 int idx = verticalHeaderItem(i)->data(Qt::UserRole).toInt();
136 molecule *mol = molecules->ReturnIndex(idx);
137 if(state){
138 emit moleculeSelected(mol);
139 }
140 else{
141 emit moleculeUnSelected(mol);
142 }
143 molSelection[i]=state;
144 }
145 }
146}
Note: See TracBrowser for help on using the repository browser.