source: src/UIElements/Views/Qt4/QtWorldView.cpp@ 41815a3

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 41815a3 was 41815a3, checked in by Michael Ankele <ankele@…>, 13 years ago

QtWorldView: removed usage of MoleculeListClass

  • Property mode set to 100644
File size: 5.4 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 * 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 <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 skiped so far
41const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
42const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
43
44QtWorldView::QtWorldView(QWidget * _parent) :
45 QTreeWidget (_parent),
46 Observer("QtWorldView")
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 //for (int i=0;i<metaObject()->methodCount();i++)
61 // std::cout << metaObject()->method(i).signature() << " - " << metaObject()->method(i).methodType() << "\n";
62
63
64
65 dirty = true;
66 clearing = false;
67 selecting = false;
68 refill();
69
70 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
71 connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
72
73}
74
75QtWorldView::~QtWorldView()
76{
77 World::getInstance().signOff(this);//, World::MoleculeInserted);
78 //World::getInstance().signOff(this, World::MoleculeRemoved);
79}
80
81void QtWorldView::update(Observable *publisher) {
82
83 if (selecting)
84 return;
85
86 dirty = true;
87
88 // force an update from Qt...
89 clearing = true;
90 clear();
91 clearing = false;
92}
93
94void QtWorldView::refill() {
95 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
96
97 clear();
98
99 // list of (unique) formulas in the world
100 std::vector<Formula> formula;
101
102 for (std::vector<molecule*>::const_iterator iter = molecules.begin();
103 iter != molecules.end();
104 iter++) {
105
106 // find group if already in list
107 QTreeWidgetItem *groupItem = NULL;
108 for (unsigned int j=0;j<formula.size();j++)
109 if ((*iter)->getFormula() == formula[j]){
110 groupItem = topLevelItem(j);
111 break;
112 }
113
114 // new molecule type -> create new group
115 if (!groupItem){
116 formula.push_back((*iter)->getFormula());
117 groupItem = new QTreeWidgetItem(this);
118 groupItem->setText(0, QString((*iter)->getName().c_str()));
119 groupItem->setText(1, QString::number((*iter)->getAtomCount()));
120 groupItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
121 groupItem->setText(3, "0");
122 groupItem->setData(0, Qt::UserRole, QVariant(-1));
123 }
124
125 // add molecule
126 QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem);
127 molItem->setText(0, QString((*iter)->getName().c_str()));
128 molItem->setText(1, QString::number((*iter)->getAtomCount()));
129 molItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
130 const int index = (*iter)->getId();
131 molItem->setData(0, Qt::UserRole, QVariant(index));
132 molItem->setSelected(World::getInstance().isSelected(*iter));
133
134
135 // increase group occurrence
136 int count = groupItem->text(3).toInt() + 1;
137 groupItem->setText(3, QString::number(count));
138 }
139 dirty = false;
140}
141
142void QtWorldView::paintEvent(QPaintEvent * event)
143{
144 if (dirty)
145 refill();
146 QTreeWidget::paintEvent(event);
147}
148
149void QtWorldView::subjectKilled(Observable *publisher) {
150}
151
152void QtWorldView::moleculeChanged() {
153 /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
154 molecule *mol = molecules->ReturnIndex(idx);
155 string cellValue = item(row,NAME)->text().toStdString();
156 if(mol->getName() != cellValue && cellValue !="") {
157 mol->setName(cellValue);
158 }
159 else if(cellValue==""){
160 item(row,NAME)->setText(QString(mol->getName().c_str()));
161 }*/
162}
163
164void QtWorldView::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){
165
166 if (clearing)
167 return;
168 if (selecting)
169 return;
170 selecting = true;
171
172 // Select all molecules which belong to newly selected rows.
173 QModelIndex index;
174 QModelIndexList items = selected.indexes();
175 foreach (index, items)
176 if (index.column() == 0){
177 int mol_id = model()->data(index, Qt::UserRole).toInt();
178 if (mol_id < 0)
179 continue;
180 //std::cout << "select molecule" << std::endl;
181 MoleCuilder::SelectionMoleculeById(mol_id);
182 }
183
184 // Unselect all molecules which belong to newly unselected rows.
185 items = deselected.indexes();
186 foreach (index, items)
187 if (index.column() == 0){
188 int mol_id = model()->data(index, Qt::UserRole).toInt();
189 if (mol_id < 0)
190 continue;
191 //std::cout << "unselect molecule" << std::endl;
192 MoleCuilder::SelectionNotMoleculeById(mol_id);
193 }
194
195 selecting = false;
196}
Note: See TracBrowser for help on using the repository browser.