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 | * QTMoleculeView.cpp
|
---|
10 | *
|
---|
11 | * Created on: Mar 4, 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/QTMoleculeView.hpp"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 |
|
---|
24 | #include "Helpers/MemDebug.hpp"
|
---|
25 |
|
---|
26 | #include "molecule.hpp"
|
---|
27 |
|
---|
28 | using namespace std;
|
---|
29 |
|
---|
30 | /***************** Basic structure for tab layout ***********/
|
---|
31 |
|
---|
32 | QTMoleculeView::QTMoleculeView() :
|
---|
33 | QTabWidget()
|
---|
34 | {
|
---|
35 | allPage = new QTAllMoleculePage();
|
---|
36 | addTab(allPage,QString("All Molecules"));
|
---|
37 |
|
---|
38 | connect(this,SIGNAL(addMolecule(molecule*)),allPage,SLOT(addMolecule(molecule*)));
|
---|
39 | connect(this,SIGNAL(removeMolecule(molecule*)),allPage,SLOT(removeMolecule(molecule*)));
|
---|
40 | }
|
---|
41 |
|
---|
42 | QTMoleculeView::~QTMoleculeView()
|
---|
43 | {}
|
---|
44 |
|
---|
45 | void QTMoleculeView::moleculeSelected(molecule *mol){
|
---|
46 | if(!pages.count(mol)){
|
---|
47 | string molName = mol->GetName();
|
---|
48 | QTMoleculePage *molPage = new QTMoleculePage(mol,molName);
|
---|
49 | addTab(molPage,QString(molName.c_str()));
|
---|
50 | pages[mol] = molPage;
|
---|
51 |
|
---|
52 | connect(molPage,SIGNAL(nameChanged(QTMoleculePage*,std::string)),this,SLOT(nameChanged(QTMoleculePage*,std::string)));
|
---|
53 |
|
---|
54 | emit addMolecule(mol);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | void QTMoleculeView::moleculeUnSelected(molecule *mol){
|
---|
59 | if(pages.count(mol)){
|
---|
60 | QTMoleculePage *molPage = pages[mol];
|
---|
61 | removeTab(indexOf(molPage));
|
---|
62 | pages.erase(mol);
|
---|
63 | delete molPage;
|
---|
64 | emit removeMolecule(mol);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | void QTMoleculeView::nameChanged(QTMoleculePage *page, std::string name){
|
---|
69 | setTabText(indexOf(page),QString(name.c_str()));
|
---|
70 | }
|
---|
71 |
|
---|
72 | /************************ Tab for all Molecules ********************/
|
---|
73 |
|
---|
74 | QTAllMoleculePage::QTAllMoleculePage() :
|
---|
75 | Observer("QTAllMoleculePage")
|
---|
76 | {}
|
---|
77 |
|
---|
78 | void QTAllMoleculePage::addMolecule(molecule *mol){}
|
---|
79 |
|
---|
80 | void QTAllMoleculePage::removeMolecule(molecule *mol){}
|
---|
81 |
|
---|
82 | void QTAllMoleculePage::update(Observable *subject){}
|
---|
83 |
|
---|
84 | void QTAllMoleculePage::subjectKilled(Observable *subject){}
|
---|
85 |
|
---|
86 | /************************ Tab for single Molecules *****************/
|
---|
87 |
|
---|
88 | QTMoleculePage::QTMoleculePage(molecule *_mol, string _name) :
|
---|
89 | Observer("QTMoleculePage"),
|
---|
90 | mol(_mol), name(_name)
|
---|
91 | {
|
---|
92 | mol->signOn(this);
|
---|
93 | }
|
---|
94 |
|
---|
95 | QTMoleculePage::~QTMoleculePage(){
|
---|
96 | mol->signOff(this);
|
---|
97 | }
|
---|
98 |
|
---|
99 | void QTMoleculePage::update(Observable *subject){
|
---|
100 | if(name != mol->GetName()){
|
---|
101 | name = mol->GetName();
|
---|
102 | emit nameChanged(this,name);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | void QTMoleculePage::subjectKilled(Observable *subject){}
|
---|