forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulationcraftqt.hpp
404 lines (351 loc) · 10.1 KB
/
simulationcraftqt.hpp
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================
#ifndef SIMULATIONCRAFTQT_H
#define SIMULATIONCRAFTQT_H
#include <QtCore/QTranslator>
#include <QtGui/QtGui>
#include <QtNetwork/QtNetwork>
#if defined( Q_OS_MAC )
#include <CoreFoundation/CoreFoundation.h>
#endif
#include <QtWidgets/QtWidgets>
class SC_MainWindow;
class SC_SearchBox;
class SC_TextEdit;
class SC_RelativePopup;
class SC_MainWindowCommandLine;
struct player_t;
struct sim_t;
#include "EnumeratedTab.hpp"
#include "sc_importWindow.hpp"
#include "util/generic.hpp"
#include "util/sc_recentlyclosed.hpp" // remove once implementations are moved to source files
#include "util/sc_searchbox.hpp" // remove once implementations are moved to source files
#include "util/sc_textedit.hpp" // remove once implementations are moved to source files
#include "util/string_view.hpp"
enum main_tabs_e
{
TAB_WELCOME = 0,
TAB_IMPORT,
TAB_OPTIONS,
TAB_SIMULATE,
TAB_RESULTS,
TAB_OVERRIDES,
TAB_HELP,
TAB_LOG,
TAB_SPELLQUERY,
TAB_COUNT
};
class SC_WebView;
// class SC_SpellQueryTab;
class SC_CommandLine;
class SC_SimulateThread;
class SC_AddonImportTab;
class SC_ImportThread;
inline QString webEngineName()
{
return "WebEngine";
}
struct SC_PATHS
{
static QStringList getDataPaths();
};
// ============================================================================
// SC_ReforgeButtonGroup
// ============================================================================
class SC_ReforgeButtonGroup : public QButtonGroup
{
Q_OBJECT
public:
SC_ReforgeButtonGroup( QObject* parent = nullptr );
private:
int selected;
private slots:
void setSelected( int id, bool checked );
};
// ============================================================================
// SC_QueueItemModel
// ============================================================================
class SC_QueueItemModel : public QStandardItemModel
{
Q_OBJECT
public:
SC_QueueItemModel( QObject* parent = nullptr ) : QStandardItemModel( parent )
{
connect( this, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), this,
SLOT( rowsRemovedSlot( const QModelIndex&, int, int ) ) );
connect( this, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), this,
SLOT( rowsInsertedSlot( const QModelIndex&, int, int ) ) );
}
void enqueue( const QString& title, const QString& options, const QString& fullOptions )
{
QStandardItem* item = new QStandardItem;
item->setData( QVariant::fromValue<QString>( title ), Qt::DisplayRole );
item->setData( QVariant::fromValue<QString>( options ), Qt::UserRole );
item->setData( QVariant::fromValue<QString>( fullOptions ), Qt::UserRole + 1 );
appendRow( item );
}
std::tuple<QString, QString> dequeue()
{
QModelIndex indx = index( 0, 0 );
std::tuple<QString, QString> retval;
if ( indx.isValid() )
{
retval = std::make_tuple( indx.data( Qt::DisplayRole ).toString(), indx.data( Qt::UserRole + 1 ).toString() );
removeRow( 0 );
}
return retval;
}
bool isEmpty() const
{
return rowCount() <= 0;
}
private slots:
void rowsRemovedSlot( const QModelIndex& parent, int start, int end )
{
Q_UNUSED( parent );
Q_UNUSED( start );
Q_UNUSED( end );
}
void rowsInsertedSlot( const QModelIndex& parent, int start, int end )
{
Q_UNUSED( parent );
int rowsAdded = ( end - start ) + 1; // if only one is added, end - start = 0
if ( rowsAdded == rowCount() )
{
emit( firstItemWasAdded() );
}
}
signals:
void firstItemWasAdded();
};
// ============================================================================
// SC_QueueListView
// ============================================================================
class SC_QueueListView : public QWidget
{
Q_OBJECT
QListView* listView;
SC_QueueItemModel* model;
int minimumItemsToShow;
public:
SC_QueueListView( SC_QueueItemModel* model, int minimumItemsToShowWidget = 1, QWidget* parent = nullptr )
: QWidget( parent ), listView( nullptr ), model( model ), minimumItemsToShow( minimumItemsToShowWidget )
{
init();
}
SC_QueueItemModel* getModel()
{
return model;
}
void setMinimumNumberOfItemsToShowWidget( int number )
{
minimumItemsToShow = number;
tryShow();
tryHide();
}
protected:
void init()
{
QVBoxLayout* widgetLayout = new QVBoxLayout;
widgetLayout->addWidget( initListView() );
QWidget* buttons = new QWidget( this );
QPushButton* buttonOne = new QPushButton( tr( "test" ) );
QHBoxLayout* buttonsLayout = new QHBoxLayout;
buttonsLayout->addWidget( buttonOne );
buttons->setLayout( buttonsLayout );
widgetLayout->addWidget( buttons );
setLayout( widgetLayout );
tryHide();
}
QListView* initListView()
{
delete listView;
listView = new QListView( this );
listView->setEditTriggers( QAbstractItemView::NoEditTriggers );
listView->setSelectionMode( QListView::SingleSelection );
listView->setModel( model );
if ( model != nullptr )
{
connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), this, SLOT( rowsInserted() ) );
connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), this, SLOT( rowsRemoved() ) );
}
QAction* remove = new QAction( tr( "Remove" ), listView );
listView->addAction( remove );
listView->setContextMenuPolicy( Qt::ActionsContextMenu );
connect( remove, SIGNAL( triggered( bool ) ), this, SLOT( removeCurrentItem() ) );
return listView;
}
void tryHide()
{
if ( model != nullptr ) // gcc gave a weird error when making this one if
{
if ( model->rowCount() < minimumItemsToShow && minimumItemsToShow >= 0 )
{
if ( isVisible() )
{
hide();
}
}
}
}
void tryShow()
{
if ( model != nullptr )
{
if ( model->rowCount() >= minimumItemsToShow )
{
if ( !isVisible() )
{
show();
}
}
}
}
private slots:
void removeCurrentItem()
{
QItemSelectionModel* selection = listView->selectionModel();
QModelIndex index = selection->currentIndex();
model->removeRow( index.row(), selection->currentIndex().parent() );
}
void rowsInserted()
{
tryShow();
}
void rowsRemoved()
{
tryHide();
}
};
// ============================================================================
// SC_CommandLine
// ============================================================================
class SC_CommandLine : public QLineEdit
{
Q_OBJECT
public:
SC_CommandLine( QWidget* parent = nullptr );
signals:
void switchToLeftSubTab();
void switchToRightSubTab();
void currentlyViewedTabCloseRequest();
};
// ============================================================================
// SC_MainNavigationWidget
// ============================================================================
// ============================================================================
// SC_MainTabWidget
// ============================================================================
class SC_MainTab : public SC_enumeratedTab<main_tabs_e>
{
Q_OBJECT
public:
SC_MainTab( QWidget* parent = nullptr ) : SC_enumeratedTab<main_tabs_e>( parent )
{
}
};
// ============================================================================
// SC_ResultTabWidget
// ============================================================================
enum result_tabs_e
{
TAB_HTML = 0,
TAB_TEXT,
TAB_JSON,
TAB_PLOTDATA
};
class SC_ResultTab : public SC_RecentlyClosedTab
{
Q_OBJECT
SC_MainWindow* mainWindow;
public:
SC_ResultTab( SC_MainWindow* );
public slots:
void TabCloseRequest( int index )
{
assert( index < count() );
if ( count() > 0 )
{
int confirm =
QMessageBox::question( this, tr( "Close Results Tab" ), tr( "Do you really want to close these results?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if ( confirm == QMessageBox::Yes )
{
setCurrentIndex( index - 1 );
removeTab( index );
}
}
}
};
class SC_SingleResultTab : public SC_enumeratedTab<result_tabs_e>
{
Q_OBJECT
SC_MainWindow* mainWindow;
public:
SC_SingleResultTab( SC_MainWindow* mw, QWidget* parent = nullptr )
: SC_enumeratedTab<result_tabs_e>( parent ), mainWindow( mw )
{
connect( this, SIGNAL( currentChanged( int ) ), this, SLOT( TabChanged( int ) ) );
}
void save_result();
public slots:
void TabChanged( int index );
};
class SC_ImportThread : public QThread
{
Q_OBJECT
SC_MainWindow* mainWindow;
std::shared_ptr<sim_t> sim;
public:
int tab;
QString url;
QString profile;
QString item_db_sources;
QString active_spec;
QString m_role;
QString api;
QString error;
player_t* player;
QString region, realm, character, spec; // New import uses these
void importWidget();
void start( std::shared_ptr<sim_t> s, int t, const QString& u, const QString& sources, const QString& spec,
const QString& role, const QString& apikey )
{
sim = s;
tab = t;
url = u;
profile = "";
item_db_sources = sources;
player = nullptr;
active_spec = spec;
m_role = role, api = apikey;
error = "";
QThread::start();
}
void start( std::shared_ptr<sim_t> s, const QString&, const QString&, const QString&, const QString& );
void run() override;
SC_ImportThread( SC_MainWindow* mw ) : mainWindow( mw ), sim( nullptr ), tab( 0 ), player( nullptr )
{
}
};
class SC_OverridesTab : public SC_TextEdit
{
Q_OBJECT
public:
SC_OverridesTab( QWidget* parent ) : SC_TextEdit( parent )
{
setPlainText( tr( "# User-specified persistent global and player parameters will be set here.\n" ) );
}
};
namespace util
{
// explicit conversion of string_view to QString
inline QString to_QString( string_view sv )
{
return QString::fromUtf8( sv.data(), as<int>( sv.size() ) );
}
} // namespace util
#endif // SIMULATIONCRAFTQT_H