OSDN Git Service

[denncoCreator] Implemented change cell and cell code type command functionality.
[dennco/denncoCreator.git] / Source / visualizer / toolwindow / dccellcodetypecombobox.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on Oct-15, 2012.
18 //
19
20 #include "dccellcodetypecombobox.h"
21
22 #include "dccreator.h"
23 #include "dccontainer.h"
24 #include "dccellcode.h"
25
26 DCCellCodeTypeComboBox::DCCellCodeTypeComboBox(DCCreator *creator, QWidget *parent) :
27     QComboBox(parent), d_creator(creator), d_cellCode(NULL)
28 {
29     DCContainer *container = d_creator->getCurrentContainer();
30
31     QList<QString> list = creator->getCurrentContainer()->getAvailableCellTypes();
32     for (int i = 0; i < list.length(); i++)
33     {
34         if (container->getIsScriptable(list.at(i)))
35         {
36             addItem(list.at(i));
37         }
38     }
39     connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotCurrentIndexChanged(QString)));
40 }
41
42 DCCellCodeTypeComboBox::~DCCellCodeTypeComboBox()
43 {
44
45 }
46
47 void DCCellCodeTypeComboBox::changeType(const QString &newType)
48 {
49     for (int i = 0; i < count(); i++)
50     {
51         if (itemText(i) == newType)
52         {
53             setCurrentIndex(i);
54             break;
55         }
56     }
57 }
58
59 void DCCellCodeTypeComboBox::setEditingCellCode(DCCellCode *cellcode)
60 {
61     d_cellCode = cellcode;
62     updateSelection();
63 }
64
65 void DCCellCodeTypeComboBox::updateSelection()
66 {
67     if (d_cellCode)
68     {
69         changeType(QString::fromStdString(d_cellCode->getCellAPIName()));
70     }
71 }
72
73 void DCCellCodeTypeComboBox::slotCurrentIndexChanged(const QString &newType)
74 {
75     if (QString::fromStdString(d_cellCode->getCellAPIName()) != newType)
76     {
77         d_creator->doCommandChangeCellCodeClassType(this, d_cellCode, newType);
78         emit typeChanged(newType);
79     }
80 }