forked from sstsimulator/sst-workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DialogManageModules.cpp
239 lines (195 loc) · 8.26 KB
/
DialogManageModules.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2015 Sandia Corporation. Under the terms
// of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2015, Sandia Corporation
// All rights reserved.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#include "DialogManageModules.h"
#include "ui_DialogManageModules.h"
//////////////////////////////////////////////////////////////////////////////
DialogManageModules::DialogManageModules(GraphicItemComponent* SelectedComponent, SSTInfoData* InfoData, QWidget* parent) :
QDialog(parent),
ui(new Ui::DialogManageModules)
{
// Init Variables
m_SelectedComponent = NULL;
m_SSTInfoData = NULL;
// Build the UI
ui->setupUi(this);
// Set the title
setWindowTitle(MANAGEMODULESDLG_DLGTITLE);
// Save the selected component
m_SelectedComponent = SelectedComponent;
m_SSTInfoData = InfoData;
// Setup the Tables
SetupTables();
}
DialogManageModules::~DialogManageModules()
{
delete ui;
}
void DialogManageModules::SetupTables()
{
PopulateAvailableModulesTable();
PopulateComponentModulesTable();
}
void DialogManageModules::PopulateComponentModulesTable()
{
int x;
int NumModulesInComponent;
QString ModuleName;
NumModulesInComponent = m_SelectedComponent->GetModulesList().size();
for (x = 0; x < NumModulesInComponent; x++) {
ModuleName = m_SelectedComponent->GetModulesList().at(x);
AddModuleNameToComponentSide(ModuleName);
}
}
void DialogManageModules::PopulateAvailableModulesTable()
{
int x;
int y;
int NumElements;
int NumModules;
SSTInfoDataElement* Element;
SSTInfoDataModule* Module;
QString FullModuleName;
QListWidgetItem* NewItem;
// Walk through all the elements and find all the modules.
NumElements = m_SSTInfoData->GetNumOfElements();
for (x = 0; x < NumElements; x++) {
Element = m_SSTInfoData->GetElement(x);
// Walk through all the Modules
NumModules = Element->GetNumOfModules();
for (y = 0; y < NumModules; y++) {
Module = Element->GetModule(y);
FullModuleName = Element->GetElementName() + "." + Module->GetModuleName();
// Create a new list item & set its data ptr to the parameter list
NewItem = new QListWidgetItem(FullModuleName);
// Save a Pointer to the Module as part of this list item so we can get it later
NewItem->setData(Qt::UserRole, VPtr<SSTInfoDataModule>::asQVariant(Module));
// NOTE: To get the data back out from this list itme use:
// SSTInfoDataModule* ptrModule = VPtr<SSTInfoDataModule>::asPtr(item->data(Qt::UserRole));
// Now add this Module name to the list
ui->listWidgetAvailableModules->addItem(NewItem);
}
}
}
void DialogManageModules::AddModuleNameToComponentSide(QString ModuleName)
{
int x;
QList<QListWidgetItem*> FoundAvailableListItems;
// Find all the items that match this name from the Available Modules List
FoundAvailableListItems = ui->listWidgetAvailableModules->findItems(ModuleName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
// For all the items found, add them to the Component List, and HIDE them from the Available List
for (x = 0; x < FoundAvailableListItems.size(); x++) {
ui->listWidgetComponentModules->addItem(ModuleName);
FoundAvailableListItems.at(x)->setHidden(true);
}
}
void DialogManageModules::RemoveModuleNameFromComponentSide(QString ModuleName)
{
int x;
QList<QListWidgetItem*> FoundAvailableListItems;
QList<QListWidgetItem*> FoundComponentListItems;
// Find all the items that match this name from the Available Modules List and Components Modules List
FoundAvailableListItems = ui->listWidgetAvailableModules->findItems(ModuleName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
FoundComponentListItems = ui->listWidgetComponentModules->findItems(ModuleName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
// For all the items found, remove them to the Component List, and UNHIDE them from the Available List
for (x = 0; x < FoundComponentListItems.size(); x++) {
ui->listWidgetComponentModules->takeItem(ui->listWidgetComponentModules->row(FoundComponentListItems.at(x)));
}
for (x = 0; x < FoundAvailableListItems.size(); x++) {
FoundAvailableListItems.at(x)->setHidden(false);
}
}
void DialogManageModules::SaveData()
{
int x;
int y;
QStringList ModuleNamesList;
QListWidgetItem* ComponentListItem;
SSTInfoDataModule* ptrModule;
SSTInfoDataParam* ptrParam;
// Build a string list of modules
for (x = 0; x < ui->listWidgetComponentModules->count(); x++) {
ComponentListItem = ui->listWidgetComponentModules->item(x);
ModuleNamesList.append(ComponentListItem->text());
}
// Add the list of modules to the component
m_SelectedComponent->SetModulesList(ModuleNamesList);
// Now Add the properties of each module to the Component,
// NOTE: Duplicate properties already in the component list will not be added
// by the properties object
// Look at each module to see if it is hidden (yes means its in the Component Modules list)
for (x = 0; x < ui->listWidgetAvailableModules->count(); x++) {
ComponentListItem = ui->listWidgetAvailableModules->item(x);
ptrModule = VPtr<SSTInfoDataModule>::asPtr(ComponentListItem->data(Qt::UserRole));
if (ComponentListItem->isHidden() == true) {
// For each param of the module, add it to the Component
for (y = 0; y < ptrModule->GetNumOfParams(); y++) {
ptrParam = ptrModule->GetParam(y);
m_SelectedComponent->AddModuleParameter(ptrParam->GetParamName(), ptrParam->GetDefaultValue(), ptrParam->GetParamDesc());
}
}
}
// Update the Visual display of the component and its properties
emit m_SelectedComponent->ItemComponentRefreshPropertiesWindow(m_SelectedComponent->GetItemProperties());
m_SelectedComponent->UpdateVisualLayoutOfComponent();
}
void DialogManageModules::on_BtnMoveLeft_clicked()
{
int x;
QList<QListWidgetItem*> SelectedListItems;
// Get all the selected items from the Available Modules List
SelectedListItems = ui->listWidgetAvailableModules->selectedItems();
// For all the items selected, add them to the Component List
for (x = 0; x < SelectedListItems.size(); x++) {
AddModuleNameToComponentSide(SelectedListItems.at(x)->text());
// Turn off selection
SelectedListItems.at(x)->setSelected(false);
}
}
void DialogManageModules::on_BtnMoveRight_clicked()
{
int x;
QList<QListWidgetItem*> SelectedListItems;
// Get all the selected items from the Component Modules List
SelectedListItems = ui->listWidgetComponentModules->selectedItems();
// For all the items selected, remove them from the Component List
for (x = 0; x < SelectedListItems.size(); x++) {
RemoveModuleNameFromComponentSide(SelectedListItems.at(x)->text());
// Turn off selection
SelectedListItems.at(x)->setSelected(false);
}
}
void DialogManageModules::on_closeButton_clicked()
{
// Save the Data entered
SaveData();
// Close the Modal Dialog
done(0);
}
void DialogManageModules::keyPressEvent(QKeyEvent* evt)
{
// Did the user click Escape?
if (Qt::Key_Escape == evt->key()) {
// Save the Data entered
SaveData();
// Close the Modal Dialog
this->close();
}
}
void DialogManageModules::on_listWidgetAvailableModules_itemDoubleClicked(QListWidgetItem *item)
{
AddModuleNameToComponentSide(item->text());
}
void DialogManageModules::on_listWidgetComponentModules_itemDoubleClicked(QListWidgetItem *item)
{
RemoveModuleNameFromComponentSide(item->text());
}