-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainWindow.h
269 lines (244 loc) · 6.74 KB
/
MainWindow.h
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#ifdef _WIN32
#include <windows.h>
#endif
#include <unordered_map>
#include <QMainWindow>
#include <QDateTime>
#include <QSettings>
#include <QCloseEvent>
#include <QTimer>
#include <QSortFilterProxyModel>
#include <QMessageBox>
#include <QApplication>
#include <QSoundEffect>
#include <QStandardPaths>
#include <QMutex>
#include <QWaitCondition>
#include <QStatusBar>
#include <QComboBox>
#include <QColor>
#include <QItemEditorFactory>
#include "Equipment.h"
#include "Ship.h"
#include "Star.h"
#include "Planet.h"
#include "BlackHole.h"
#include "Galaxy.h"
#include "TradeTableModel.h"
#include "EquipmentTableModel.h"
#include "HierarchicalHeaderView.h"
#include "BlackHolesTableModel.h"
#include "PlanetsTableModel.h"
#include "SortMultiFilterProxyModel.h"
#include "FilterHorizontalHeaderView.h"
namespace Ui {
class MainWindow;
}
QStringList supportedColors();
class ColorListEditor : public QComboBox
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
public:
ColorListEditor(QWidget *widget = 0): QComboBox(widget)
{
populateList(supportedColors());
}
public:
QColor color() const
{
return qvariant_cast<QColor>(itemData(currentIndex(), Qt::DecorationRole));
}
void setColor(QColor c)
{
setCurrentIndex(findData(c, int(Qt::DecorationRole)));
}
private:
void populateList(const QStringList& colorNames)
{
for (int i = 0; i < colorNames.size(); ++i) {
QColor color(colorNames[i]);
insertItem(i, colorNames[i]);
setItemData(i, color, Qt::DecorationRole);
}
}
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void readSettings();
void writeSettings() const;
void closeEvent(QCloseEvent *event);
public slots:
bool parseDump(const QString &filename=QString());
bool openDump();
void showAbout();
void saveReport();
void saveAllReports();
void setMapScale(int width)
{
mapWidth=width;
updateMap();
}
void setMapFontSize(int pt)
{
mapFontSize=pt;
updateMap();
}
void loadNextDump();
void loadPreviousDump();
#ifdef _WIN32
public slots:
virtual bool nativeEvent(const QByteArray &eventType, void *message, long*);
void saveDumpWin();
public:
bool simulateInput(const std::string& str) const;
QImage currentScreen(float kx, float ky, float kw, float kh);
#endif
private slots:
void customHeaderMenuRequested(QPoint pos);
private:
// using Scorer=std::vector<std::tuple<QString,double,bool>>;
struct Scorer
{
void read(const QVariantMap& map);
void addPreset(const QString presetName,double weight,bool isBool,bool depthPenalize);
double score(const QMap<QString,int>& reportSummary,const QMap<QString,QVector<int>>& _reportDepthList) const
{
double score=0.0;
const double depthOffset=100;
for(int iPreset=0; iPreset<presetNames.size(); iPreset++)
{
double numRows=reportSummary.value(presetNames[iPreset]);
if(numRows==0.0) {continue;}
numRows=areBoolean[iPreset]?std::min(numRows,1.0):numRows;
if(depthPenalized[iPreset]) {
auto depthList=_reportDepthList.value(presetNames[iPreset]);
if(areBoolean[iPreset]) {
int minDepth=*std::min_element(depthList.constBegin(), depthList.constEnd());
minDepth+=depthOffset;
score+=1.0*weights[iPreset]/minDepth;
} else {
for(int depth: depthList) {
depth+=depthOffset;
score+=1.0*weights[iPreset]/depth;
}
}
} else {
score+=numRows*weights[iPreset];
}
}
return score;
}
QVector<QString> presetNames;
QVector<double> weights;
QVector<bool> areBoolean;
QVector<bool> depthPenalized;
};
void showMessage(const QString& str,int timeout=0) const
{
std::cout<<str.toStdString()<<std::endl;
statusBar()->showMessage(str,timeout);
}
bool openDump(const QString& fileName);
void savePreset(const QVariantMap& preset, const QString& fileName) const;
void generateGalaxies();
void responsiveSleep(int msec) const;
void loadPresets();
void updateMap();
void updateDumpArrows();
void saveMap();
bool eventFilter(QObject* object, QEvent* event);
QVariantMap loadPreset(const QString &fileName) const;
QString scoresSummary(bool desc=true) const
{
QString summary;
using MapStrScorerCI=QMap<QString,Scorer>::const_iterator;
for (MapStrScorerCI i = scorers.begin(); i != scorers.end(); ++i)
{
if(desc) {summary+=i.key()+" = ";}
summary+=QString::number(i.value().score(_reportSummary,_reportDepthList))+
"\t";
}
return summary;
}
QString scoresSummaryHeader() const
{
QString summary;
using MapStrScorerCI=QMap<QString,Scorer>::const_iterator;
for (MapStrScorerCI i = scorers.begin(); i != scorers.end(); ++i)
{
summary+=i.key()+"\t";
}
return summary;
}
QString reportSummary(bool desc=true) const
{
QString summary=scoresSummary(desc);
using MapStrIntCI=QMap<QString,int>::const_iterator;
for (MapStrIntCI i = _reportSummary.begin(); i != _reportSummary.end(); ++i)
{
if (desc) { summary+=i.key()+": ";}
summary+=QString::number(i.value())+"\t";
}
return summary;
}
QString reportSummaryHeader() const
{
QString summary="dump name\t"+scoresSummaryHeader();
using MapStrIntCI=QMap<QString,int>::const_iterator;
for (MapStrIntCI i = _reportSummary.begin(); i != _reportSummary.end(); ++i)
{
summary+=i.key()+"\t";
}
return summary;
}
static QMap<QString,Scorer> readScorers(const QString &filename);
private:
Ui::MainWindow *ui;
QString _filename;
Galaxy galaxy;
QDateTime _fileModified;
TradeTableModel tradeModel;
QSortFilterProxyModel tradeProxyModel;
EquipmentTableModel eqModel;
FilterHorizontalHeaderView* eqHeaderView;
SortMultiFilterProxyModel eqProxyModel;
QMenu eqMenu;
unsigned eqMenuRow=0;
BlackHolesTableModel bhModel;
PlanetsTableModel planetsModel;
SortMultiFilterProxyModel planetsProxyModel;
FilterHorizontalHeaderView *planetsHeaderView;
QTimer reloadTimer;
QSpinBox _mapScaleSpinBox{this};
QSpinBox _mapFontSpinBox{this};
QMenu reloadMenu;
QMenu saveReportMenu;
QSoundEffect sound;
const QString rangersDir=QStandardPaths::locate(QStandardPaths::DocumentsLocation,"SpaceRangersHD",QStandardPaths::LocateDirectory);
const QString presetDirPlanets="presets/planets/";
const QString presetDirEq="presets/equipment/";
const QString presetDirPlanetsReport="presets/planetsReport/";
const QString presetDirEqReport="presets/equipmentReport/";
int maxGenerationTime=120000;
int screenSaveLag=200;
int shortSleep=25;
unsigned mapWidth=700;
unsigned mapFontSize=8;
QStringList planetsReportPresets;
QStringList eqReportPresets;
QMap<QString,int> minRowsPreset;
QMap<QString,int> _reportSummary;
QMap<QString,QVector<int>> _reportDepthList;
QStringList dumpFileList;
int currentDumpIndex=-1;
QImage galaxyMap;
QMap<QString,Scorer> scorers;
};
#endif // MAINWINDOW_H