source: src/UIElements/Views/Qt4/QtElementList.cpp@ 7305d5

Last change on this file since 7305d5 was 94d5ac6, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[0e6156]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[0e6156]21 */
22
23/*
24 * QtElementList.cpp
25 *
26 * Created on: Mar 6, 2012
27 * Author: ankele
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/QtElementList.hpp"
36
37#include <iostream>
38
39#include "CodePatterns/MemDebug.hpp"
40
41#include "Atom/atom.hpp"
42#include "Formula.hpp"
43#include "molecule.hpp"
44#include "MoleculeListClass.hpp"
45
46#include "Element/element.hpp"
47#include "Element/periodentafel.hpp"
[59a28e]48#include "Descriptors/AtomTypeDescriptor.hpp"
49#include <QAbstractItemView>
[1de61e]50#include "Actions/SelectionAction/Atoms/AtomByElementAction.hpp"
51#include "Actions/SelectionAction/Atoms/NotAtomByElementAction.hpp"
[0e6156]52
53using namespace std;
54
55const int QtElementList::COLUMNCOUNT = COLUMNTYPES_MAX;
[59a28e]56const char *QtElementList::COLUMNNAMES[QtElementList::COLUMNCOUNT]={"Number","Name","Symbol","Mass","Occurrence"};
[0e6156]57
58QtElementList::QtElementList(QWidget * _parent) :
[f20fa5]59 QTreeWidget (_parent),
[0e6156]60 Observer("QtElementList")
61{
[f20fa5]62 setColumnCount(COLUMNCOUNT);
[59a28e]63 setSelectionMode(QAbstractItemView::MultiSelection);
[0e6156]64
[f20fa5]65 QStringList header;
66 for(int i=0; i<COLUMNCOUNT;++i)
67 header << COLUMNNAMES[i];
68 setHeaderLabels(header);
[0e6156]69
[25b3559]70 dirty = true;
71 refill();
[818201]72
[0e6156]73 molecules = World::getInstance().getMolecules();
74 molecules->signOn(this);
75
[25b3559]76 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
77 connect(this,SIGNAL(changed()),this,SLOT(update()));
[59a28e]78}
79
80QtElementList::~QtElementList()
81{
82 molecules->signOff(this);
83}
84
85void QtElementList::update(Observable *publisher) {
86
[25b3559]87 dirty = true;
88
89 // force an update from Qt...
90 clear();
91 //emit changed(); doesn't work!?!
92}
93
94void QtElementList::refill() {
95
[0e6156]96 periodentafel *&periode = World::getInstance().getPeriode();
[f20fa5]97
[1de61e]98 elementSelection.clear();
99
[f20fa5]100 int i;
[59a28e]101
102 clear();
[f20fa5]103 periodentafel::const_iterator iter;
104 for(iter = periode->begin(),i=0;
105 iter != periode->end();
106 ++i,++iter) {
107 const element *e = iter->second;
[59a28e]108 int count = 0;
109 count = World::getInstance().getAllAtoms(AtomByType(e)).size();
[f20fa5]110
111 QTreeWidgetItem *treeItem = new QTreeWidgetItem(this);
[1de61e]112 treeItem->setText(NUMBER, QString::number(e->getAtomicNumber()));
113 treeItem->setText(NAME, QString(e->getName().c_str()));
114 treeItem->setText(SYMBOL, QString(e->getSymbol().c_str()));
115 treeItem->setText(MASS, QString::number(e->getMass()));
[59a28e]116 if (count > 0){
[1de61e]117 treeItem->setText(OCCURRENCE, QString::number(count));
[59a28e]118 }else{
[1de61e]119 treeItem->setText(OCCURRENCE, "none");
[59a28e]120 treeItem->setDisabled(true);
121 }
[1de61e]122 elementSelection.push_back(treeItem->isSelected());
[0e6156]123 }
[25b3559]124 dirty = false;
125}
126
127void QtElementList::paintEvent(QPaintEvent * event)
128{
129 if (dirty)
130 refill();
131 QTreeWidget::paintEvent(event);
[0e6156]132}
133
134void QtElementList::subjectKilled(Observable *publisher) {
135}
136
137
[1de61e]138void QtElementList::rowSelected()
[0e6156]139{
[1de61e]140 //std::cout << "rowSelected\n";
141 periodentafel *&periode = World::getInstance().getPeriode();
142
143 for (int i=0;i<topLevelItemCount();i++){
144 QTreeWidgetItem *item = topLevelItem(i);
145 bool newSelection = item->isSelected();
146 if (newSelection != elementSelection[i]){
147 elementSelection[i] = newSelection;
148
149 int atomicNumber = item->text(NUMBER).toInt();
150 const element *e = periode->FindElement(atomicNumber);
151 if (newSelection)
152 MoleCuilder::SelectionAtomByElement(e);
153 else
154 MoleCuilder::SelectionNotAtomByElement(e);
155 }
156 }
[0e6156]157}
158
Note: See TracBrowser for help on using the repository browser.