source: src/UIElements/Views/Qt4/QtWorldView.cpp@ ad011c

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

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 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.hpp"
27#include "Formula.hpp"
28#include "molecule.hpp"
29
30using namespace std;
31
32// maybe this should go with the definition of molecules
33
34// some attributes need to be easier to find for molecules
35// these attributes are skiped so far
36const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
37const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula"/*,"Size"*/};
38
39QtWorldView::QtWorldView(QWidget * _parent) :
40 QTableWidget (_parent),
41 Observer("QtWorldView")
42{
43 setRowCount(0);
44 setColumnCount(COLUMNCOUNT);
45
46 for(int i=0; i<COLUMNCOUNT;++i) {
47 QTableWidgetItem *heading = new QTableWidgetItem();
48 heading->setText(QString(COLUMNNAMES[i]));
49 setHorizontalHeaderItem(i,heading);
50 }
51
52 molecules = World::getInstance().getMolecules();
53 molecules->signOn(this);
54 update(molecules);
55
56 connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
57 connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
58
59}
60
61QtWorldView::~QtWorldView()
62{
63 molecules->signOff(this);
64}
65
66void QtWorldView::update(Observable *publisher) {
67 int numMolecules = molecules->ListOfMolecules.size();
68 setRowCount(numMolecules);
69 molSelection.resize(numMolecules);
70 int i;
71 MoleculeList::iterator iter;
72 for(iter = molecules->ListOfMolecules.begin(),i=0;
73 iter != molecules->ListOfMolecules.end();
74 ++i,++iter) {
75
76 const int index = (*iter)->IndexNr;
77 QTableWidgetItem *indexWidget = new QTableWidgetItem();
78 indexWidget->setText(QString::number(index));
79 indexWidget->setData(Qt::UserRole,QVariant(index));
80 setVerticalHeaderItem(i,indexWidget);
81
82 const string name = (*iter)->getName();
83 QTableWidgetItem *nameWidget = new QTableWidgetItem();
84 nameWidget->setText(QString(name.c_str()));
85 setItem(i,NAME,nameWidget);
86
87 const int atomCount = (*iter)->getAtomCount();
88 QTableWidgetItem *countWidget= new QTableWidgetItem();
89 countWidget->setText(QString::number(atomCount));
90 countWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
91 setItem(i,ATOMS,countWidget);
92
93 const Formula formula = (*iter)->getFormula();
94 QTableWidgetItem *formulaWidget= new QTableWidgetItem();
95 formulaWidget->setText(QString(formula.toString().c_str()));
96 formulaWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
97 setItem(i,ATOMS,formulaWidget);
98
99 molSelection[i]=nameWidget->isSelected();
100 }
101}
102
103void QtWorldView::subjectKilled(Observable *publisher) {
104}
105
106void QtWorldView::moleculeChanged(int row, int column) {
107 int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
108 molecule *mol = molecules->ReturnIndex(idx);
109 string cellValue = item(row,NAME)->text().toStdString();
110 if(mol->getName() != cellValue && cellValue !="") {
111 mol->setName(cellValue);
112 }
113 else if(cellValue==""){
114 item(row,NAME)->setText(QString(mol->getName().c_str()));
115 }
116}
117
118
119void QtWorldView::cellSelected(int row, int column){
120 bool state = item(row,column)->isSelected();
121 for(int i = 0; i<COLUMNCOUNT; i++){
122 item(row,i)->setSelected(state);
123 }
124 // figure out which rows have changed
125 for(int i=0; i<rowCount();++i){
126 state = item(i,0)->isSelected();
127 if(molSelection[i]!=state){
128 int idx = verticalHeaderItem(i)->data(Qt::UserRole).toInt();
129 molecule *mol = molecules->ReturnIndex(idx);
130 if(state){
131 emit moleculeSelected(mol);
132 }
133 else{
134 emit moleculeUnSelected(mol);
135 }
136 molSelection[i]=state;
137 }
138 }
139}
Note: See TracBrowser for help on using the repository browser.