-
Notifications
You must be signed in to change notification settings - Fork 122
/
QtReflMainView.cpp
299 lines (264 loc) · 9.61 KB
/
QtReflMainView.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include "MantidQtCustomInterfaces/QtReflMainView.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include "MantidQtCustomInterfaces/ReflMainViewPresenter.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidKernel/ConfigService.h"
#include <qinputdialog.h>
#include <qmessagebox.h>
namespace MantidQt
{
namespace CustomInterfaces
{
using namespace Mantid::API;
DECLARE_SUBWINDOW(QtReflMainView);
//----------------------------------------------------------------------------------------------
/** Constructor
*/
QtReflMainView::QtReflMainView(QWidget *parent) : UserSubWindow(parent)
{
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
QtReflMainView::~QtReflMainView()
{
}
/**
Initialise the Interface
*/
void QtReflMainView::initLayout()
{
ui.setupUi(this);
ui.workspaceSelector->refresh();
//Expand the process runs column at the expense of the search column
ui.splitterTables->setStretchFactor(0, 0);
ui.splitterTables->setStretchFactor(1, 1);
//Zero out the progress bar
ui.progressBar->setRange(0, 100);
ui.progressBar->setValue(0);
//Allow rows to be reordered
ui.viewTable->verticalHeader()->setMovable(true);
connect(ui.workspaceSelector, SIGNAL(activated(QString)), this, SLOT(setModel(QString)));
connect(ui.actionSaveTable, SIGNAL(triggered()), this, SLOT(actionSave()));
connect(ui.actionSaveTableAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
connect(ui.actionNewTable, SIGNAL(triggered()), this, SLOT(actionNewTable()));
connect(ui.actionAddRow, SIGNAL(triggered()), this, SLOT(actionAddRow()));
connect(ui.actionDeleteRow, SIGNAL(triggered()), this, SLOT(actionDeleteRow()));
connect(ui.actionProcess, SIGNAL(triggered()), this, SLOT(actionProcess()));
connect(ui.actionGroupRows, SIGNAL(triggered()), this, SLOT(actionGroupRows()));
//Finally, create a presenter to do the thinking for us
m_presenter = boost::shared_ptr<IReflPresenter>(new ReflMainViewPresenter(this));
}
/**
This slot loads a table workspace model and changes to a LoadedMainView presenter
@param name : the string name of the workspace to be grabbed
*/
void QtReflMainView::setModel(QString name)
{
m_toOpen = name.toStdString();
m_presenter->notify(OpenTableFlag);
}
/**
Set a new model in the tableview
@param model : the model to be attached to the tableview
*/
void QtReflMainView::showTable(ITableWorkspace_sptr model)
{
QAbstractItemModel* qModel = new QReflTableModel(model);
//So we can notify the presenter when the user updates the table
connect(qModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(tableUpdated(const QModelIndex&, const QModelIndex&)));
ui.viewTable->setModel(qModel);
ui.viewTable->resizeColumnsToContents();
}
/**
This slot notifies the presenter that the "save" button has been pressed
*/
void QtReflMainView::actionSave()
{
m_presenter->notify(SaveFlag);
}
/**
This slot notifies the presenter that the "save as" button has been pressed
*/
void QtReflMainView::actionSaveAs()
{
m_presenter->notify(SaveAsFlag);
}
/**
This slot notifies the presenter that the "add row" button has been pressed
*/
void QtReflMainView::actionAddRow()
{
m_presenter->notify(AddRowFlag);
}
/**
This slot notifies the presenter that the "delete" button has been pressed
*/
void QtReflMainView::actionDeleteRow()
{
m_presenter->notify(DeleteRowFlag);
}
/**
This slot notifies the presenter that the "process" button has been pressed
*/
void QtReflMainView::actionProcess()
{
m_presenter->notify(ProcessFlag);
}
/**
This slot notifies the presenter that the "group rows" button has been pressed
*/
void QtReflMainView::actionGroupRows()
{
m_presenter->notify(GroupRowsFlag);
}
/**
This slot notifies the presenter that the "new table" button as been pressed
*/
void QtReflMainView::actionNewTable()
{
m_presenter->notify(NewTableFlag);
}
/**
This slot notifies the presenter that the table has been updated/changed by the user
*/
void QtReflMainView::tableUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
m_presenter->notify(TableUpdatedFlag);
}
/**
Show an information dialog
@param prompt : The prompt to appear on the dialog
@param title : The text for the title bar of the dialog
*/
void QtReflMainView::giveUserInfo(std::string prompt, std::string title)
{
QMessageBox::information(this,QString(title.c_str()),QString(prompt.c_str()),QMessageBox::Ok, QMessageBox::Ok);
}
/**
Show an critical error dialog
@param prompt : The prompt to appear on the dialog
@param title : The text for the title bar of the dialog
*/
void QtReflMainView::giveUserCritical(std::string prompt, std::string title)
{
QMessageBox::critical(this,QString(title.c_str()),QString(prompt.c_str()),QMessageBox::Ok, QMessageBox::Ok);
}
/**
Show a warning dialog
@param prompt : The prompt to appear on the dialog
@param title : The text for the title bar of the dialog
*/
void QtReflMainView::giveUserWarning(std::string prompt, std::string title)
{
QMessageBox::warning(this,QString(title.c_str()),QString(prompt.c_str()),QMessageBox::Ok, QMessageBox::Ok);
}
/**
Ask the user a Yes/No question
@param prompt : The prompt to appear on the dialog
@param title : The text for the title bar of the dialog
@returns a boolean true if Yes, false if No
*/
bool QtReflMainView::askUserYesNo(std::string prompt, std::string title)
{
auto response = QMessageBox::question(this,QString(title.c_str()),QString(prompt.c_str()),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
if (response == QMessageBox::Yes)
{
return true;
}
return false;
}
/**
Ask the user to enter a string.
@param prompt : The prompt to appear on the dialog
@param title : The text for the title bar of the dialog
@param defaultValue : The default value entered.
@returns The user's string if submitted, or an empty string
*/
std::string QtReflMainView::askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue)
{
bool ok;
QString text = QInputDialog::getText(QString::fromStdString(title), QString::fromStdString(prompt), QLineEdit::Normal, QString::fromStdString(defaultValue), &ok);
if(ok)
return text.toStdString();
return "";
}
/**
Set the range of the progress bar
@param min : The minimum value of the bar
@param max : The maxmimum value of the bar
*/
void QtReflMainView::setProgressRange(int min, int max)
{
ui.progressBar->setRange(min, max);
}
/**
Set the status of the progress bar
@param progress : The current value of the bar
*/
void QtReflMainView::setProgress(int progress)
{
ui.progressBar->setValue(progress);
}
/**
Set the list of available instruments to search and process for
@param instruments : The list of instruments available
@param defaultInstrument : The instrument to have selected by default
*/
void QtReflMainView::setInstrumentList(const std::vector<std::string>& instruments, const std::string& defaultInstrument)
{
ui.comboSearchInstrument->clear();
ui.comboProcessInstrument->clear();
for(auto it = instruments.begin(); it != instruments.end(); ++it)
{
QString instrument = QString::fromStdString(*it);
ui.comboSearchInstrument->addItem(instrument);
ui.comboProcessInstrument->addItem(instrument);
}
int index = ui.comboSearchInstrument->findData(QString::fromStdString(defaultInstrument), Qt::DisplayRole);
ui.comboSearchInstrument->setCurrentIndex(index);
ui.comboProcessInstrument->setCurrentIndex(index);
}
/**
Get the selected instrument for searching
@returns the selected instrument to search for
*/
std::string QtReflMainView::getSearchInstrument() const
{
return ui.comboSearchInstrument->currentText().toStdString();
}
/**
Get the selected instrument for processing
@returns the selected instrument to process with
*/
std::string QtReflMainView::getProcessInstrument() const
{
return ui.comboProcessInstrument->currentText().toStdString();
}
/**
Get the indices of the highlighted rows
@returns a vector of unsigned ints contianing the highlighted row numbers
*/
std::vector<size_t> QtReflMainView::getSelectedRowIndexes() const
{
auto selectedRows = ui.viewTable->selectionModel()->selectedRows();
//auto selectedType = ui.viewTable->selectionModel()->;
std::vector<size_t> rowIndexes;
for (auto idx = selectedRows.begin(); idx != selectedRows.end(); ++idx)
{
rowIndexes.push_back(idx->row());
}
return rowIndexes;
}
/**
Get the name of the workspace that the user wishes to open as a table
@returns The name of the workspace to open
*/
std::string QtReflMainView::getWorkspaceToOpen() const
{
return m_toOpen;
}
} // namespace CustomInterfaces
} // namespace Mantid