source: src/UIElements/Views/QT4/QTWorldView.cpp@ 9cd807

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 9cd807 was 26cf17, checked in by Frederik Heber <heber@…>, 14 years ago

Added Formula WidgetItem to QTWorldView.

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