source: src/UIElements/Views/Qt4/QtMoleculeList.cpp@ eb0d77

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

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

  • Property mode set to 100644
File size: 5.3 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.
[bcf653]5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[b47bfc]8/*
[0eb7bf3]9 * QtMoleculeList.cpp
[b47bfc]10 *
11 * Created on: Jan 21, 2010
12 * Author: crueger
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
[bbbad5]19
[0eb7bf3]20#include "Views/Qt4/QtMoleculeList.hpp"
[b47bfc]21
[41815a3]22#include <QMetaMethod>
23
[b47bfc]24#include <iostream>
25
[ad011c]26#include "CodePatterns/MemDebug.hpp"
[bbbad5]27
[6f0841]28#include "Atom/atom.hpp"
[26cf17]29#include "Formula.hpp"
[b47bfc]30#include "molecule.hpp"
[42127c]31#include "MoleculeListClass.hpp"
[b14efe]32#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
33#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
[b47bfc]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
[6cab535]40// these attributes are skipped so far
[0eb7bf3]41const int QtMoleculeList::COLUMNCOUNT = COLUMNTYPES_MAX;
42const char *QtMoleculeList::COLUMNNAMES[QtMoleculeList::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
[b47bfc]43
[0eb7bf3]44QtMoleculeList::QtMoleculeList(QWidget * _parent) :
[79b59b]45 QTreeWidget (_parent),
[0eb7bf3]46 Observer("QtMoleculeList")
[b47bfc]47{
48 setColumnCount(COLUMNCOUNT);
[79b59b]49 setSelectionMode(QAbstractItemView::MultiSelection);
[b47bfc]50
[79b59b]51 QStringList header;
52 for(int i=0; i<COLUMNCOUNT;++i)
53 header << COLUMNNAMES[i];
54 setHeaderLabels(header);
[b47bfc]55
[41815a3]56 World::getInstance().signOn(this);//, World::MoleculeInserted);
57 //World::getInstance().signOn(this, World::MoleculeRemoved);
58
59
[a39006]60 dirty = true;
[99e8ea]61 clearing = false;
[41815a3]62 selecting = false;
[a39006]63 refill();
[b47bfc]64
[79b59b]65 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
[41815a3]66 connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
[b47bfc]67
68}
69
[0eb7bf3]70QtMoleculeList::~QtMoleculeList()
[b47bfc]71{
[41815a3]72 World::getInstance().signOff(this);//, World::MoleculeInserted);
73 //World::getInstance().signOff(this, World::MoleculeRemoved);
[b47bfc]74}
75
[0eb7bf3]76void QtMoleculeList::update(Observable *publisher) {
[a39006]77
[41815a3]78 if (selecting)
79 return;
80
[a39006]81 dirty = true;
82
83 // force an update from Qt...
[99e8ea]84 clearing = true;
[a39006]85 clear();
[99e8ea]86 clearing = false;
[a39006]87}
88
[0eb7bf3]89void QtMoleculeList::refill() {
[6cab535]90 clearing = true;
[41815a3]91 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
92
[79b59b]93 clear();
94
95 // list of (unique) formulas in the world
96 std::vector<Formula> formula;
97
[41815a3]98 for (std::vector<molecule*>::const_iterator iter = molecules.begin();
99 iter != molecules.end();
100 iter++) {
[b47bfc]101
[79b59b]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");
[41815a3]118 groupItem->setData(0, Qt::UserRole, QVariant(-1));
[79b59b]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()));
[41815a3]126 const int index = (*iter)->getId();
[79b59b]127 molItem->setData(0, Qt::UserRole, QVariant(index));
[b14efe]128 molItem->setSelected(World::getInstance().isSelected(*iter));
[79b59b]129
130
131 // increase group occurrence
132 int count = groupItem->text(3).toInt() + 1;
133 groupItem->setText(3, QString::number(count));
[b47bfc]134 }
[a39006]135 dirty = false;
[6cab535]136 clearing = false;
[a39006]137}
138
[0eb7bf3]139void QtMoleculeList::paintEvent(QPaintEvent * event)
[a39006]140{
141 if (dirty)
142 refill();
143 QTreeWidget::paintEvent(event);
[b47bfc]144}
145
[0eb7bf3]146void QtMoleculeList::subjectKilled(Observable *publisher) {
[b47bfc]147}
148
[0eb7bf3]149void QtMoleculeList::moleculeChanged() {
[79b59b]150 /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
[b47bfc]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()));
[79b59b]158 }*/
[b47bfc]159}
160
[0eb7bf3]161void QtMoleculeList::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){
[b14efe]162
[99e8ea]163 if (clearing)
164 return;
[41815a3]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 }
[99e8ea]180
[41815a3]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);
[b47bfc]190 }
[41815a3]191
192 selecting = false;
[b47bfc]193}
Note: See TracBrowser for help on using the repository browser.