[48eab8] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2017 Frederik Heber. All rights reserved.
|
---|
| 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/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * QtGeometryList.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Mar 25, 2017
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "Views/Qt4/QtGeometryList.hpp"
|
---|
| 36 |
|
---|
| 37 | #include <iostream>
|
---|
| 38 |
|
---|
| 39 | //#include "CodePatterns/MemDebug.hpp"
|
---|
| 40 |
|
---|
| 41 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
| 42 | #include "CodePatterns/toString.hpp"
|
---|
| 43 |
|
---|
| 44 | #include "Geometry/GeometryRegistry.hpp"
|
---|
| 45 |
|
---|
| 46 | #include <QAbstractItemView>
|
---|
| 47 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
| 50 | const int QtGeometryList::COLUMNCOUNT = COLUMNTYPES_MAX;
|
---|
| 51 | const char *QtGeometryList::COLUMNNAMES[QtGeometryList::COLUMNCOUNT]={"Name","Vector"};
|
---|
| 52 |
|
---|
| 53 | QtGeometryList::QtGeometryList(QWidget * _parent) :
|
---|
| 54 | QTreeWidget (_parent),
|
---|
| 55 | Observer("QtGeometryList")
|
---|
| 56 | {
|
---|
| 57 | setColumnCount(COLUMNCOUNT);
|
---|
| 58 | setSelectionMode(QAbstractItemView::NoSelection);
|
---|
| 59 |
|
---|
| 60 | QStringList header;
|
---|
| 61 | for(int i=0; i<COLUMNCOUNT;++i)
|
---|
| 62 | header << COLUMNNAMES[i];
|
---|
| 63 | setHeaderLabels(header);
|
---|
| 64 |
|
---|
| 65 | refill(NULL);
|
---|
| 66 |
|
---|
| 67 | GeometryRegistry::getInstance().signOn(this);
|
---|
| 68 | GeometryRegistry::getInstance().signOn(this, GeometryRegistry::GeometryInserted);
|
---|
| 69 | GeometryRegistry::getInstance().signOn(this, GeometryRegistry::GeometryRemoved);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | QtGeometryList::~QtGeometryList()
|
---|
| 73 | {
|
---|
| 74 | GeometryRegistry::getInstance().signOff(this);
|
---|
| 75 | GeometryRegistry::getInstance().signOff(this, GeometryRegistry::GeometryInserted);
|
---|
| 76 | GeometryRegistry::getInstance().signOff(this, GeometryRegistry::GeometryRemoved);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void QtGeometryList::update(Observable *publisher) {}
|
---|
| 80 |
|
---|
| 81 | void QtGeometryList::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
| 82 | {
|
---|
| 83 | if (static_cast<GeometryRegistry*>(publisher) == GeometryRegistry::getPointer()) {
|
---|
| 84 | switch (notification->getChannelNo()) {
|
---|
| 85 | case GeometryRegistry::GeometryInserted:
|
---|
| 86 | {
|
---|
| 87 | refill(NULL);
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | case GeometryRegistry::GeometryRemoved:
|
---|
| 91 | {
|
---|
| 92 | refill(GeometryRegistry::getInstance().lastChanged());
|
---|
| 93 | break;
|
---|
| 94 | }
|
---|
| 95 | default:
|
---|
| 96 | ASSERT(0, "QtGeometryList::recieveNotification() - we cannot get here.");
|
---|
| 97 | break;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void QtGeometryList::refill(::GeometryObject *ignore)
|
---|
| 103 | {
|
---|
| 104 | clear();
|
---|
| 105 |
|
---|
| 106 | GeometryRegistry ® = GeometryRegistry::getInstance();
|
---|
| 107 |
|
---|
| 108 | GeometryRegistry::const_iterator iter;
|
---|
| 109 | for (iter = reg.getBeginIter(); iter != reg.getEndIter(); iter ++){
|
---|
| 110 | ::GeometryObject *v = iter->second;
|
---|
| 111 | if (v == ignore)
|
---|
| 112 | continue;
|
---|
| 113 |
|
---|
| 114 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(this);
|
---|
| 115 | treeItem->setText(NAME, QString(v->getName().c_str()));
|
---|
| 116 | treeItem->setText(VECTOR, QString(toString(v->getVector()).c_str()));
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | #if 0
|
---|
| 121 | void QtGeometryList::paintEvent(QPaintEvent * event)
|
---|
| 122 | {
|
---|
| 123 | /*if (dirty)
|
---|
| 124 | refill(NULL);*/
|
---|
| 125 | QtGeometryList::paintEvent(event);
|
---|
| 126 | }
|
---|
| 127 | #endif
|
---|
| 128 |
|
---|
| 129 | void QtGeometryList::subjectKilled(Observable *publisher) {
|
---|
| 130 | }
|
---|