| 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 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
|---|
| 34 | #include <QAbstractItemView>
|
|---|
| 35 |
|
|---|
| 36 | using namespace std;
|
|---|
| 37 |
|
|---|
| 38 | const int QtElementList::COLUMNCOUNT = COLUMNTYPES_MAX;
|
|---|
| 39 | const char *QtElementList::COLUMNNAMES[QtElementList::COLUMNCOUNT]={"Number","Name","Symbol","Mass","Occurrence"};
|
|---|
| 40 |
|
|---|
| 41 | QtElementList::QtElementList(QWidget * _parent) :
|
|---|
| 42 | QTreeWidget (_parent),
|
|---|
| 43 | Observer("QtElementList")
|
|---|
| 44 | {
|
|---|
| 45 | setColumnCount(COLUMNCOUNT);
|
|---|
| 46 | setSelectionMode(QAbstractItemView::MultiSelection);
|
|---|
| 47 |
|
|---|
| 48 | QStringList header;
|
|---|
| 49 | for(int i=0; i<COLUMNCOUNT;++i)
|
|---|
| 50 | header << COLUMNNAMES[i];
|
|---|
| 51 | setHeaderLabels(header);
|
|---|
| 52 |
|
|---|
| 53 | dirty = false;
|
|---|
| 54 |
|
|---|
| 55 | molecules = World::getInstance().getMolecules();
|
|---|
| 56 | molecules->signOn(this);
|
|---|
| 57 | update(molecules);
|
|---|
| 58 |
|
|---|
| 59 | connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | QtElementList::~QtElementList()
|
|---|
| 63 | {
|
|---|
| 64 | molecules->signOff(this);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void QtElementList::update(Observable *publisher) {
|
|---|
| 68 |
|
|---|
| 69 | periodentafel *&periode = World::getInstance().getPeriode();
|
|---|
| 70 |
|
|---|
| 71 | int i;
|
|---|
| 72 |
|
|---|
| 73 | clear();
|
|---|
| 74 | periodentafel::const_iterator iter;
|
|---|
| 75 | for(iter = periode->begin(),i=0;
|
|---|
| 76 | iter != periode->end();
|
|---|
| 77 | ++i,++iter) {
|
|---|
| 78 | const element *e = iter->second;
|
|---|
| 79 | int count = 0;
|
|---|
| 80 | count = World::getInstance().getAllAtoms(AtomByType(e)).size();
|
|---|
| 81 |
|
|---|
| 82 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(this);
|
|---|
| 83 | treeItem->setText(0, QString::number(e->getAtomicNumber()));
|
|---|
| 84 | treeItem->setText(1, QString(e->getName().c_str()));
|
|---|
| 85 | treeItem->setText(2, QString(e->getSymbol().c_str()));
|
|---|
| 86 | treeItem->setText(3, QString::number(e->getMass()));
|
|---|
| 87 | if (count > 0){
|
|---|
| 88 | treeItem->setText(4, QString::number(count));
|
|---|
| 89 | }else{
|
|---|
| 90 | treeItem->setText(4, "none");
|
|---|
| 91 | treeItem->setDisabled(true);
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void QtElementList::subjectKilled(Observable *publisher) {
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | void QtElementList::cellSelected(int row, int column)
|
|---|
| 101 | {
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|