source: src/UIElements/Views/Qt4/QtWorldView.cpp@ 3b229e

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

QtWorldView: selection in widget calls actions

  • Property mode set to 100644
File size: 4.9 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 <iostream>
23
24#include "CodePatterns/MemDebug.hpp"
25
26#include "Atom/atom.hpp"
27#include "Formula.hpp"
28#include "molecule.hpp"
29#include "MoleculeListClass.hpp"
30#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
31#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
32
33using namespace std;
34
35// maybe this should go with the definition of molecules
36
37// some attributes need to be easier to find for molecules
38// these attributes are skiped so far
39const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
40const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
41
42QtWorldView::QtWorldView(QWidget * _parent) :
43 QTreeWidget (_parent),
44 Observer("QtWorldView")
45{
46 setColumnCount(COLUMNCOUNT);
47 setSelectionMode(QAbstractItemView::MultiSelection);
48
49 QStringList header;
50 for(int i=0; i<COLUMNCOUNT;++i)
51 header << COLUMNNAMES[i];
52 setHeaderLabels(header);
53
54 molecules = World::getInstance().getMolecules();
55 molecules->signOn(this);
56 update(molecules);
57
58 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
59 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
60
61}
62
63QtWorldView::~QtWorldView()
64{
65 molecules->signOff(this);
66}
67
68void QtWorldView::update(Observable *publisher) {
69 int numMolecules = molecules->ListOfMolecules.size();
70 clear();
71 molSelection.resize(numMolecules);
72
73 // list of (unique) formulas in the world
74 std::vector<Formula> formula;
75
76 int i;
77 MoleculeList::iterator iter;
78 for(iter = molecules->ListOfMolecules.begin(),i=0;
79 iter != molecules->ListOfMolecules.end();
80 ++i,++iter) {
81
82 // find group if already in list
83 QTreeWidgetItem *groupItem = NULL;
84 for (unsigned int j=0;j<formula.size();j++)
85 if ((*iter)->getFormula() == formula[j]){
86 groupItem = topLevelItem(j);
87 break;
88 }
89
90 // new molecule type -> create new group
91 if (!groupItem){
92 formula.push_back((*iter)->getFormula());
93 groupItem = new QTreeWidgetItem(this);
94 groupItem->setText(0, QString((*iter)->getName().c_str()));
95 groupItem->setText(1, QString::number((*iter)->getAtomCount()));
96 groupItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
97 groupItem->setText(3, "0");
98 }
99
100 // add molecule
101 QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem);
102 molItem->setText(0, QString((*iter)->getName().c_str()));
103 molItem->setText(1, QString::number((*iter)->getAtomCount()));
104 molItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
105 const int index = (*iter)->IndexNr;
106 molItem->setData(0, Qt::UserRole, QVariant(index));
107 molItem->setSelected(World::getInstance().isSelected(*iter));
108
109
110 // increase group occurrence
111 int count = groupItem->text(3).toInt() + 1;
112 groupItem->setText(3, QString::number(count));
113
114 //molSelection[i]=nameWidget->isSelected();
115 }
116}
117
118void QtWorldView::subjectKilled(Observable *publisher) {
119}
120
121void QtWorldView::moleculeChanged() {
122 /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
123 molecule *mol = molecules->ReturnIndex(idx);
124 string cellValue = item(row,NAME)->text().toStdString();
125 if(mol->getName() != cellValue && cellValue !="") {
126 mol->setName(cellValue);
127 }
128 else if(cellValue==""){
129 item(row,NAME)->setText(QString(mol->getName().c_str()));
130 }*/
131}
132
133
134void QtWorldView::rowSelected(){
135
136 // lookup all molecules in the treeWidget
137 for (int i=0;i<topLevelItemCount();i++){
138 QTreeWidgetItem *top = topLevelItem(i);
139 for (int j=0;j<top->childCount();j++){
140
141 // molecules are 1 level below the top
142 QTreeWidgetItem *molItem = top->child(j);
143
144 // molecule index stored as user data
145 int index = molItem->data(0, Qt::UserRole).toInt();
146 molecule *mol = molecules->ReturnIndex(index);
147 ASSERT(mol, "QtWorldView::rowSelected()");
148
149 // selection changed by user?
150 bool molSelectedWorld = World::getInstance().isSelected(mol);
151 bool molSelectedList = molItem->isSelected();
152 //std::cout << molSelectedWorld << " " << molSelectedList << std::endl;
153
154 if (molSelectedWorld != molSelectedList){
155
156 // apply new selection state
157 if (molSelectedList){
158 //std::cout << "select molecule" << std::endl;
159 MoleCuilder::SelectionMoleculeById(mol->getId());
160 }else{
161 //std::cout << "unselect molecule" << std::endl;
162 MoleCuilder::SelectionNotMoleculeById(mol->getId());
163 }
164 }
165 }
166 }
167}
Note: See TracBrowser for help on using the repository browser.