source: src/UIElements/Views/QT4/QTWorldView.cpp@ bbbad5

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

Added MemDebug.hpp to each and every .cpp file (were it was still missing).

  • is topmost include and separated by a newline from rest.
  • NOTE: QT includes have to appear before MemDebug.hpp due to strange magic happening therein.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * QTWorldView.cpp
3 *
4 * Created on: Jan 21, 2010
5 * Author: crueger
6 */
7
8
9#include "Views/QT4/QTWorldView.hpp"
10
11#include <iostream>
12
13#include "Helpers/MemDebug.hpp"
14
15#include "atom.hpp"
16#include "molecule.hpp"
17
18using namespace std;
19
20// maybe this should go with the definition of molecules
21
22// some attributes need to be easier to find for molecules
23// these attributes are skiped so far
24const int QTWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
25const char *QTWorldView::COLUMNNAMES[QTWorldView::COLUMNCOUNT]={"Name","Atoms"/*,"Formula"*//*,"Size"*/};
26
27QTWorldView::QTWorldView(QWidget * _parent) :
28 QTableWidget (_parent),
29 Observer("QTWorldView")
30{
31 setRowCount(0);
32 setColumnCount(COLUMNCOUNT);
33
34 for(int i=0; i<COLUMNCOUNT;++i) {
35 QTableWidgetItem *heading = new QTableWidgetItem();
36 heading->setText(QString(COLUMNNAMES[i]));
37 setHorizontalHeaderItem(i,heading);
38 }
39
40 molecules = World::getInstance().getMolecules();
41 molecules->signOn(this);
42 update(molecules);
43
44 connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
45 connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
46
47}
48
49QTWorldView::~QTWorldView()
50{
51 molecules->signOff(this);
52}
53
54void QTWorldView::update(Observable *publisher) {
55 int numMolecules = molecules->ListOfMolecules.size();
56 setRowCount(numMolecules);
57 molSelection.resize(numMolecules);
58 int i;
59 MoleculeList::iterator iter;
60 for(iter = molecules->ListOfMolecules.begin(),i=0;
61 iter != molecules->ListOfMolecules.end();
62 ++i,++iter) {
63
64 const int index = (*iter)->IndexNr;
65 QTableWidgetItem *indexWidget = new QTableWidgetItem();
66 // there probably is an easier method to convert ints to QStrings... but i didn't find it
67 stringstream idxsstr;
68 idxsstr << index;
69 indexWidget->setText(QString(idxsstr.str().c_str()));
70 indexWidget->setData(Qt::UserRole,QVariant(index));
71 setVerticalHeaderItem(i,indexWidget);
72
73 const string name = (*iter)->getName();
74 QTableWidgetItem *nameWidget = new QTableWidgetItem();
75 nameWidget->setText(QString(name.c_str()));
76 setItem(i,NAME,nameWidget);
77
78 const int atomCount = (*iter)->getAtomCount();
79 QTableWidgetItem *countWidget= new QTableWidgetItem();
80 stringstream countsstr;
81 countsstr << atomCount;
82 countWidget->setText(QString(countsstr.str().c_str()));
83 countWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
84 setItem(i,ATOMS,countWidget);
85
86 molSelection[i]=nameWidget->isSelected();
87 }
88}
89
90void QTWorldView::subjectKilled(Observable *publisher) {
91}
92
93void QTWorldView::moleculeChanged(int row, int column) {
94 int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
95 molecule *mol = molecules->ReturnIndex(idx);
96 string cellValue = item(row,NAME)->text().toStdString();
97 if(mol->getName() != cellValue && cellValue !="") {
98 mol->setName(cellValue);
99 }
100 else if(cellValue==""){
101 item(row,NAME)->setText(QString(mol->getName().c_str()));
102 }
103}
104
105
106void QTWorldView::cellSelected(int row, int column){
107 bool state = item(row,column)->isSelected();
108 for(int i = 0; i<COLUMNCOUNT; i++){
109 item(row,i)->setSelected(state);
110 }
111 // figure out which rows have changed
112 for(int i=0; i<rowCount();++i){
113 state = item(i,0)->isSelected();
114 if(molSelection[i]!=state){
115 int idx = verticalHeaderItem(i)->data(Qt::UserRole).toInt();
116 molecule *mol = molecules->ReturnIndex(idx);
117 if(state){
118 emit moleculeSelected(mol);
119 }
120 else{
121 emit moleculeUnSelected(mol);
122 }
123 molSelection[i]=state;
124 }
125 }
126}
Note: See TracBrowser for help on using the repository browser.