Subversion Repositories svn1-original

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 david 1
#include "mainwindow.h"
2
#include "ui_mainwindow.h"
175 david 3
#include "qmconfteams.h"
130 david 4
#include "qmconfclass.h"
5
#include "qmconfwinners.h"
6
#include "qmteamdisplay.h"
7
#include "QMessageBox"
133 david 8
#include "QInputDialog"
134 - 9
#include "QTime"
10
#include "qmdialoglegstarttimes.h"
138 david 11
#include "qmdisqualified.h"
141 - 12
#include "qmdatacheck.h"
148 - 13
#include "qmdialogloadexternalteams.h"
149 - 14
#include "QFileDialog"
157 david 15
#include "qmdialoguploadlegtimes.h"
167 david 16
#include "qmdialogstatus.h"
172 david 17
#include "qmreportwindow.h"
173 david 18
#include "QTabWidget"
19
#include "QLayout"
192 - 20
#include "qmeventstatus.h"
215 - 21
#include "qmdownloadlegtimes.h"
225 - 22
#include "qmdialogabout.h"
130 david 23
 
24
#include    "consts.h"
25
#include    "structs.h"
26
#include    "proto.h"
27
 
28
MainWindow *mw = NULL;
29
 
30
MainWindow::MainWindow(QWidget *parent) :
31
    QMainWindow(parent),
32
    ui(new Ui::MainWindow)
33
{
34
    ui->setupUi(this);
35
    mw = this;
36
 
173 david 37
    QTabWidget *tabWidget = new QTabWidget();
38
    setCentralWidget(tabWidget);
130 david 39
 
175 david 40
    tabWidget->addTab( new QmConfTeams,    "Configure");
173 david 41
    tabWidget->addTab( new QmConfClass,    "Class");
42
    tabWidget->addTab( new QmConfWinners,  "Winners");
193 - 43
    tabWidget->addTab( new QmEventStatus,  "Status");
173 david 44
    tabWidget->addTab( new qmTeamDisplay,  "Team Data");
45
    tabWidget->addTab( new qmDisqualified, "Disqual");
46
    tabWidget->addTab( new qmDataCheck,    "Data Check");
207 - 47
    tabWidget->addTab( reportWindow = new QmReportWindow, "Reports");
173 david 48
 
198 david 49
    QMenu *m0 = new QMenu ("Team");
144 david 50
    ui->menuBar->addMenu(m0);
51
    m0->addAction("Reset All Team Data", this, SLOT(resetTeamData()));
52
    m0->addAction("Generate dummy team names", this, SLOT(generateDummyTeamNames()));
53
 
131 - 54
    QMenu *m1 = new QMenu ("Leg Time Setup");
55
    ui->menuBar->addMenu(m1);
56
    m1->addAction("Clear ALL Leg Times", this, SLOT(clearLegTimes()));
133 david 57
    m1->addAction("Clear single leg start times", this, SLOT(ClearOneLegTimes()));
144 david 58
    m1->addSeparator();
59
    m1->addAction("Set Start Times", this, SLOT(setStartTimes()));
207 - 60
    m1->addSeparator();
133 david 61
    m1->addAction("Set calculated leg start", this, SLOT(setCalcLegStart()));
135 david 62
    m1->addAction("Set ordered incremental leg start", this, SLOT(setOrderedIncLegStart()));
63
    m1->addAction("Set staggered start time", this, SLOT(setStaggeredLegStart()));
64
    m1->addAction("Set fixed start time", this, SLOT(setFixedLegStart()));
244 - 65
    m1->addSeparator();
66
    m1->addAction("Recalculate elapsed times", this, SLOT(recalcLegTimes()));
144 david 67
 
68
    QMenu *m2 = new QMenu ("Upload");
69
    ui->menuBar->addMenu(m2);
148 - 70
    m2->addAction("Load team information from external file", this, SLOT(loadExternalTeams()));
157 david 71
    m2->addAction("Upload time information", this, SLOT(uploadLegData()));
144 david 72
 
215 - 73
    QMenu *m3 = new QMenu ("Export");
160 - 74
    ui->menuBar->addMenu(m3);
215 - 75
    m3->addAction("Store team information to external file", this, SLOT(storeExternalTeams()));
76
    m3->addAction("Create external leg data file", this, SLOT(storeLegData()));
77
 
78
    QMenu *m4 = new QMenu ("Reports");
79
    ui->menuBar->addMenu(m4);
80
    m4->addAction("Generate All Reports", this, SLOT(generateReports()));
81
    m4->addAction("Display Summary", this, SLOT(displaySummary()));
225 - 82
 
83
    ui->menuBar->addAction("About", this, SLOT(showAbout()));
130 david 84
}
85
 
86
MainWindow::~MainWindow()
87
{
88
    delete ui;
89
}
90
 
137 david 91
void MainWindow::showMessage( const QString & msg, int timeout)
92
{
93
    if ( mw )
94
    {
95
        mw->ui->statusBar->showMessage(msg, timeout);
96
    }
97
}
98
 
207 - 99
void MainWindow::registerReport(const QString &report, const QString &name)
100
{
101
    if (mw && mw->reportWindow)
102
    {
103
        mw->reportWindow->addReport(report, name);
104
    }
105
}
106
 
130 david 107
void MainWindow::changeEvent(QEvent *e)
108
{
109
    QMainWindow::changeEvent(e);
110
    switch (e->type()) {
111
    case QEvent::LanguageChange:
112
        ui->retranslateUi(this);
113
        break;
114
    default:
115
        break;
116
    }
117
}
118
 
119
void MainWindow::setStartTimes(void)
120
{
131 - 121
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
135 david 122
                                    tr("This will reset the start times for all teams based on the Category configuration.\n"
130 david 123
                                       "Are you sure you want to do this?"),
124
                                    QMessageBox::Cancel,
125
                                    QMessageBox::Ok))
126
    {
131 - 127
        leg_start();
130 david 128
    }
131 - 129
 
130 david 130
}
131
 
131 - 132
void MainWindow::clearLegTimes(void)
133
{
134
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
135
                                    tr("This will clear ALL leg times for ALL teams.\n"
136
                                       "Are you sure you want to do this?"),
137
                                    QMessageBox::Cancel,
138
                                    QMessageBox::Ok))
139
    {
140
        leg_ini();
141
    }
142
}
143
 
144
void MainWindow::resetTeamData(void)
145
{
146
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
147
                                    tr("This will clear ALL team information.\n"
148
                                       "Are you sure you want to do this?"),
149
                                    QMessageBox::Cancel,
150
                                    QMessageBox::Ok))
151
    {
152
        tm_init();
153
    }
154
}
155
 
132 - 156
void MainWindow::generateDummyTeamNames(void)
157
{
158
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
159
                                    tr("This will generate DUMMY team names.\n"
160
                                       "Are you sure you want to do this?"),
161
                                    QMessageBox::Cancel,
162
                                    QMessageBox::Ok))
163
    {
164
        tm_gen();
165
    }
166
}
167
 
133 david 168
void MainWindow::ClearOneLegTimes(void)
169
{
170
    bool ok;
171
    int leg = QInputDialog::getInt(this, tr("Clear One Leg Start Time"),
172
                                              tr("Leg:"), 0, 0, config.num_legs, 1, &ok);
173
    if ( ok && leg)
174
    {
137 david 175
        tm_clearleg_specified(leg, FALSE);
133 david 176
    }
177
}
178
 
179
void MainWindow::setCalcLegStart(void)
180
{
134 - 181
    QmDialogLegStartTimes dialog("Calculate Leg Start Time",this);
135 david 182
    dialog.setDeltaTimeLabel("Delta Time");
207 - 183
    dialog.setDescription("The start time is based on the end time of the previous leg with a constant Delta time added");
184
 
135 david 185
qDebug ("Must disable stuff");
134 - 186
    if ( QDialog::Accepted == dialog.exec() )
133 david 187
    {
134 - 188
        if ( dialog.getLeg() )
189
        {
190
            tm_lgs(dialog.getLeg(),
135 david 191
                   dialog.getDeltaTime(),
192
                   dialog.getReport(),
193
                   dialog.getClear() );
194
        }
195
    }
196
}
197
 
198
void MainWindow::setOrderedIncLegStart(void)
199
{
200
    QmDialogLegStartTimes dialog("Ordered Incremental Leg Start Time",this);
201
    dialog.setTimeLabel("Start Time");
202
    dialog.setDeltaTimeLabel("Delta Time");
207 - 203
    dialog.setDescription("The specified start time is given to the fastest team. Teams are then set at specified Delta from that time.");
135 david 204
    if ( QDialog::Accepted == dialog.exec() )
205
    {
206
        if ( dialog.getLeg() )
207
        {
208
            tm_lgs1(dialog.getLeg(),
134 - 209
                   dialog.getTime(),
135 david 210
                   dialog.getDeltaTime(),
134 - 211
                   dialog.getReport(),
212
                   dialog.getClear() );
213
        }
133 david 214
    }
135 david 215
}
134 - 216
 
135 david 217
void MainWindow::setStaggeredLegStart(void)
218
{
219
    QmDialogLegStartTimes dialog("Staggered Leg Start Time",this);
220
    dialog.setTimeLabel("Start Time");
221
    dialog.setDeltaTimeLabel("Stagger Time");
207 - 222
    dialog.setDescription("The lowest numbered team is given the start time. The teams are then starggered by team number from that time.");
135 david 223
    if ( QDialog::Accepted == dialog.exec() )
224
    {
225
        if ( dialog.getLeg() )
226
        {
227
            tm_staggered(dialog.getLeg(),
228
                   dialog.getTime(),
229
                   dialog.getDeltaTime(),
230
                   dialog.getReport(),
231
                   dialog.getClear() );
232
        }
233
    }
133 david 234
}
135 david 235
 
236
void MainWindow::setFixedLegStart(void)
237
{
238
    QmDialogLegStartTimes dialog("Fixed Leg Start Time",this);
239
    dialog.setTimeLabel("Start Time");
207 - 240
    dialog.setDescription("The specified start time is given to all teams.");
135 david 241
    if ( QDialog::Accepted == dialog.exec() )
242
    {
243
        if ( dialog.getLeg() )
244
        {
245
            tm_fixedstart(dialog.getLeg(),
246
                   dialog.getTime(),
247
                   //dialog.getDeltaTime(),
248
                   dialog.getReport(),
249
                   dialog.getClear() );
250
        }
251
    }
252
}
148 - 253
 
244 - 254
void MainWindow::recalcLegTimes(void)
255
{
256
    QmDialogLegStartTimes dialog("Recalc Elesped Times",this);
257
    dialog.setDescription("The elasped times for all teams is recaclulated. This should not be neeed.");
258
    if ( QDialog::Accepted == dialog.exec() )
259
    {
260
        if ( dialog.getLeg() )
261
        {
262
            tm_recalcElapsed(dialog.getLeg());
263
        }
264
    }
265
}
266
 
148 - 267
void MainWindow::loadExternalTeams(void)
268
{
149 - 269
    QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"),
178 - 270
                                                     filepath,
149 - 271
                                                     tr("Data (*.csv);;All (*.*)"),
272
                                                     0,
273
                                                     QFileDialog::ReadOnly);
274
    if ( fileName.isEmpty() )
275
    {
276
        return;
277
    }
278
 
279
    QmDialogLoadExternalTeams dialog(fileName,this);
148 - 280
    dialog.exec();
281
}
282
 
153 - 283
void MainWindow::storeExternalTeams(void)
284
{
285
    QString fileName = QFileDialog::getSaveFileName(this, tr("Store File"),
178 - 286
                                                     filepath,
153 - 287
                                                     tr("Data (*.csv);;All (*.*)"),
288
 
289
                                                     );
290
    if ( fileName.isEmpty() )
291
    {
292
        return;
293
    }
294
    MainWindow::showMessage("Writing external data");
295
    QmDialogLoadExternalTeams::storeData(fileName);
155 david 296
    MainWindow::showMessage("Writing external data completed");
153 - 297
}
298
 
156 david 299
void MainWindow::storeTeamInfo(void)
300
{
301
    QString fileName = QFileDialog::getSaveFileName(this, tr("Store Team Info File"),
178 - 302
                                                     filepath,
156 david 303
                                                     tr("Data (*.txt);;All (*.*)"),
304
 
305
                                                     );
306
    if ( fileName.isEmpty() )
307
    {
308
        return;
309
    }
310
    MainWindow::showMessage("Writing team info");
311
    QmDialogLoadExternalTeams::storeTeamInfo(fileName);
312
    MainWindow::showMessage("Writing team info completed");
313
}
314
 
157 david 315
void MainWindow::storeLegData(void)
316
{
215 - 317
    QmDownloadLegTimes dialog(this);
318
    dialog.exec();
157 david 319
}
320
 
321
void MainWindow::uploadLegData(void)
322
{
323
    QmDialogUploadLegTimes  dialog(this);
324
    dialog.exec();
325
}
326
 
160 - 327
void MainWindow::generateReports(void)
328
{
329
    if( load_report_data() )
330
    {
331
        pri_all_reports();
332
    }
333
}
334
 
167 david 335
 
165 - 336
void MainWindow::displaySummary(void)
337
{
167 david 338
    QmDialogStatus dialog(this);
339
    dialog.exec();
165 - 340
}
341
 
225 - 342
void MainWindow::showAbout(void)
343
{
344
    QmDialogAbout dialog(this);
228 - 345
    dialog.setText(QString("Build Date: ") + __DATE__ + " " + __TIME__ + "\nVersion: " + VERSION);
225 - 346
    dialog.exec();
347
}
165 - 348
 
225 - 349