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 | * QtElementList.cpp
|
---|
10 | *
|
---|
11 | * Created on: Mar 6, 2012
|
---|
12 | * Author: ankele
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Views/Qt4/QtElementList.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 |
|
---|
31 | #include "Element/element.hpp"
|
---|
32 | #include "Element/periodentafel.hpp"
|
---|
33 |
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 | const int QtElementList::COLUMNCOUNT = COLUMNTYPES_MAX;
|
---|
37 | const char *QtElementList::COLUMNNAMES[QtElementList::COLUMNCOUNT]={"Number","Name","Symbol","Mass"};
|
---|
38 |
|
---|
39 | QtElementList::QtElementList(QWidget * _parent) :
|
---|
40 | QTreeWidget (_parent),
|
---|
41 | Observer("QtElementList")
|
---|
42 | {
|
---|
43 | setColumnCount(COLUMNCOUNT);
|
---|
44 |
|
---|
45 | QStringList header;
|
---|
46 | for(int i=0; i<COLUMNCOUNT;++i)
|
---|
47 | header << COLUMNNAMES[i];
|
---|
48 | setHeaderLabels(header);
|
---|
49 | //setAllColumnsShowFocus( true );
|
---|
50 |
|
---|
51 | molecules = World::getInstance().getMolecules();
|
---|
52 | molecules->signOn(this);
|
---|
53 | update(molecules);
|
---|
54 |
|
---|
55 | periodentafel *&periode = World::getInstance().getPeriode();
|
---|
56 |
|
---|
57 |
|
---|
58 | int i;
|
---|
59 | periodentafel::const_iterator iter;
|
---|
60 | for(iter = periode->begin(),i=0;
|
---|
61 | iter != periode->end();
|
---|
62 | ++i,++iter) {
|
---|
63 | const element *e = iter->second;
|
---|
64 |
|
---|
65 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(this);
|
---|
66 | treeItem->setText(0, QString::number(e->getAtomicNumber()));
|
---|
67 | treeItem->setText(1, QString(e->getName().c_str()));
|
---|
68 | treeItem->setText(2, QString(e->getSymbol().c_str()));
|
---|
69 | treeItem->setText(3, QString::number(e->getMass()));
|
---|
70 |
|
---|
71 | /*QTableWidgetItem *indexWidget = new QTableWidgetItem();
|
---|
72 | //std::cout << "Creating index item " << indexWidget << "." << std::endl;
|
---|
73 | indexWidget->setText(QString::number(e->getAtomicNumber()));
|
---|
74 | indexWidget->setData(Qt::UserRole,QVariant(e->getAtomicNumber()));
|
---|
75 | setItem(i,NUMBER,indexWidget);
|
---|
76 |
|
---|
77 | const string name = e->getName();
|
---|
78 | QTableWidgetItem *nameWidget = new QTableWidgetItem();
|
---|
79 | //std::cout << "Creating name item " << nameWidget << " at " << i << "," << NAME << "." << std::endl;
|
---|
80 | nameWidget->setText(QString(name.c_str()));
|
---|
81 | setItem(i,NAME,nameWidget);
|
---|
82 |
|
---|
83 | const string symbol = e->getSymbol();
|
---|
84 | QTableWidgetItem *symWidget = new QTableWidgetItem();
|
---|
85 | //std::cout << "Creating symbol item " << symWidget << " at " << i << "," << NAME << "." << std::endl;
|
---|
86 | symWidget->setText(QString(symbol.c_str()));
|
---|
87 | setItem(i,SYMBOL,symWidget);
|
---|
88 |
|
---|
89 | const double mass = e->getMass();
|
---|
90 | QTableWidgetItem *massWidget= new QTableWidgetItem();
|
---|
91 | //std::cout << "Creating mass item " << massWidget << " at " << i << "," << ATOMCOUNT << "." << std::endl;
|
---|
92 | massWidget->setText(QString::number(mass));
|
---|
93 | massWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
---|
94 | setItem(i,MASS,massWidget);*/
|
---|
95 | }
|
---|
96 |
|
---|
97 | connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
|
---|
98 | connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
|
---|
99 | }
|
---|
100 |
|
---|
101 | QtElementList::~QtElementList()
|
---|
102 | {
|
---|
103 | molecules->signOff(this);
|
---|
104 | }
|
---|
105 |
|
---|
106 | void QtElementList::update(Observable *publisher) {
|
---|
107 | }
|
---|
108 |
|
---|
109 | void QtElementList::subjectKilled(Observable *publisher) {
|
---|
110 | }
|
---|
111 |
|
---|
112 | void QtElementList::moleculeChanged(int row, int column) {
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | void QtElementList::cellSelected(int row, int column)
|
---|
117 | {
|
---|
118 | }
|
---|
119 |
|
---|