source: src/UIElements/Views/Qt4/QtMoleculeList.cpp@ 52575c

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

Fix: don't execute SelectionMoleculeByIdAction during QtMoleculeList.refill()

  • Property mode set to 100644
File size: 5.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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * QtMoleculeList.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/QtMoleculeList.hpp"
21
22#include <QMetaMethod>
23
24#include <iostream>
25
26#include "CodePatterns/MemDebug.hpp"
27
28#include "Atom/atom.hpp"
29#include "Formula.hpp"
30#include "molecule.hpp"
31#include "MoleculeListClass.hpp"
32#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
33#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
34
35using namespace std;
36
37// maybe this should go with the definition of molecules
38
39// some attributes need to be easier to find for molecules
40// these attributes are skipped so far
41const int QtMoleculeList::COLUMNCOUNT = COLUMNTYPES_MAX;
42const char *QtMoleculeList::COLUMNNAMES[QtMoleculeList::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
43
44QtMoleculeList::QtMoleculeList(QWidget * _parent) :
45 QTreeWidget (_parent),
46 Observer("QtMoleculeList")
47{
48 setColumnCount(COLUMNCOUNT);
49 setSelectionMode(QAbstractItemView::MultiSelection);
50
51 QStringList header;
52 for(int i=0; i<COLUMNCOUNT;++i)
53 header << COLUMNNAMES[i];
54 setHeaderLabels(header);
55
56 World::getInstance().signOn(this);//, World::MoleculeInserted);
57 //World::getInstance().signOn(this, World::MoleculeRemoved);
58
59
60 dirty = true;
61 clearing = false;
62 selecting = false;
63 refill();
64
65 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
66 connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
67
68}
69
70QtMoleculeList::~QtMoleculeList()
71{
72 World::getInstance().signOff(this);//, World::MoleculeInserted);
73 //World::getInstance().signOff(this, World::MoleculeRemoved);
74}
75
76void QtMoleculeList::update(Observable *publisher) {
77
78 if (selecting)
79 return;
80
81 dirty = true;
82
83 // force an update from Qt...
84 clearing = true;
85 clear();
86 clearing = false;
87}
88
89void QtMoleculeList::refill() {
90 clearing = true;
91 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
92
93 clear();
94
95 // list of (unique) formulas in the world
96 std::vector<Formula> formula;
97
98 for (std::vector<molecule*>::const_iterator iter = molecules.begin();
99 iter != molecules.end();
100 iter++) {
101
102 // find group if already in list
103 QTreeWidgetItem *groupItem = NULL;
104 for (unsigned int j=0;j<formula.size();j++)
105 if ((*iter)->getFormula() == formula[j]){
106 groupItem = topLevelItem(j);
107 break;
108 }
109
110 // new molecule type -> create new group
111 if (!groupItem){
112 formula.push_back((*iter)->getFormula());
113 groupItem = new QTreeWidgetItem(this);
114 groupItem->setText(0, QString((*iter)->getName().c_str()));
115 groupItem->setText(1, QString::number((*iter)->getAtomCount()));
116 groupItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
117 groupItem->setText(3, "0");
118 groupItem->setData(0, Qt::UserRole, QVariant(-1));
119 }
120
121 // add molecule
122 QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem);
123 molItem->setText(0, QString((*iter)->getName().c_str()));
124 molItem->setText(1, QString::number((*iter)->getAtomCount()));
125 molItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
126 const int index = (*iter)->getId();
127 molItem->setData(0, Qt::UserRole, QVariant(index));
128 molItem->setSelected(World::getInstance().isSelected(*iter));
129
130
131 // increase group occurrence
132 int count = groupItem->text(3).toInt() + 1;
133 groupItem->setText(3, QString::number(count));
134 }
135 dirty = false;
136 clearing = false;
137}
138
139void QtMoleculeList::paintEvent(QPaintEvent * event)
140{
141 if (dirty)
142 refill();
143 QTreeWidget::paintEvent(event);
144}
145
146void QtMoleculeList::subjectKilled(Observable *publisher) {
147}
148
149void QtMoleculeList::moleculeChanged() {
150 /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
151 molecule *mol = molecules->ReturnIndex(idx);
152 string cellValue = item(row,NAME)->text().toStdString();
153 if(mol->getName() != cellValue && cellValue !="") {
154 mol->setName(cellValue);
155 }
156 else if(cellValue==""){
157 item(row,NAME)->setText(QString(mol->getName().c_str()));
158 }*/
159}
160
161void QtMoleculeList::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){
162
163 if (clearing)
164 return;
165 if (selecting)
166 return;
167 selecting = true;
168
169 // Select all molecules which belong to newly selected rows.
170 QModelIndex index;
171 QModelIndexList items = selected.indexes();
172 foreach (index, items)
173 if (index.column() == 0){
174 int mol_id = model()->data(index, Qt::UserRole).toInt();
175 if (mol_id < 0)
176 continue;
177 //std::cout << "select molecule" << std::endl;
178 MoleCuilder::SelectionMoleculeById(mol_id);
179 }
180
181 // Unselect all molecules which belong to newly unselected rows.
182 items = deselected.indexes();
183 foreach (index, items)
184 if (index.column() == 0){
185 int mol_id = model()->data(index, Qt::UserRole).toInt();
186 if (mol_id < 0)
187 continue;
188 //std::cout << "unselect molecule" << std::endl;
189 MoleCuilder::SelectionNotMoleculeById(mol_id);
190 }
191
192 selecting = false;
193}
Note: See TracBrowser for help on using the repository browser.