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