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