Subversion Repositories svn1

Rev

Rev 306 | Rev 311 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
126 david 1
#include "mainwindow.h"
2
#include "ui_mainwindow.h"
171 david 3
#include "qmconfteams.h"
126 david 4
#include "qmconfclass.h"
5
#include "qmconfwinners.h"
6
#include "qmteamdisplay.h"
7
#include "QMessageBox"
129 david 8
#include "QInputDialog"
130 - 9
#include "QTime"
10
#include "qmdialoglegstarttimes.h"
134 david 11
#include "qmdisqualified.h"
137 - 12
#include "qmdatacheck.h"
144 - 13
#include "qmdialogloadexternalteams.h"
145 - 14
#include "QFileDialog"
153 david 15
#include "qmdialoguploadlegtimes.h"
163 david 16
#include "qmdialogstatus.h"
168 david 17
#include "qmreportwindow.h"
169 david 18
#include "QTabWidget"
19
#include "QLayout"
188 - 20
#include "qmeventstatus.h"
211 - 21
#include "qmdownloadlegtimes.h"
221 - 22
#include "qmdialogabout.h"
293 david 23
#include "qmhttppath.h"
302 david 24
#include "qmdialogchangeteamnumber.h"
307 david 25
#include "qmfulldata.h"
126 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;
249 - 39
    setWindowTitle("Mara");
126 david 40
 
169 david 41
    QTabWidget *tabWidget = new QTabWidget();
42
    setCentralWidget(tabWidget);
126 david 43
 
171 david 44
    tabWidget->addTab( new QmConfTeams,    "Configure");
169 david 45
    tabWidget->addTab( new QmConfClass,    "Class");
46
    tabWidget->addTab( new QmConfWinners,  "Winners");
189 - 47
    tabWidget->addTab( new QmEventStatus,  "Status");
169 david 48
    tabWidget->addTab( new qmTeamDisplay,  "Team Data");
49
    tabWidget->addTab( new qmDisqualified, "Disqual");
50
    tabWidget->addTab( new qmDataCheck,    "Data Check");
307 david 51
    tabWidget->addTab( new qmFullData,     "Full Data");
203 - 52
    tabWidget->addTab( reportWindow = new QmReportWindow, "Reports");
169 david 53
 
194 david 54
    QMenu *m0 = new QMenu ("Team");
140 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()));
306 david 58
    m0->addAction("Copy/Move/Swap Team Data", this, SLOT(changeTeamNumber()));
140 david 59
 
127 - 60
    QMenu *m1 = new QMenu ("Leg Time Setup");
61
    ui->menuBar->addMenu(m1);
62
    m1->addAction("Clear ALL Leg Times", this, SLOT(clearLegTimes()));
129 david 63
    m1->addAction("Clear single leg start times", this, SLOT(ClearOneLegTimes()));
140 david 64
    m1->addSeparator();
65
    m1->addAction("Set Start Times", this, SLOT(setStartTimes()));
203 - 66
    m1->addSeparator();
129 david 67
    m1->addAction("Set calculated leg start", this, SLOT(setCalcLegStart()));
131 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()));
240 - 71
    m1->addSeparator();
72
    m1->addAction("Recalculate elapsed times", this, SLOT(recalcLegTimes()));
140 david 73
 
74
    QMenu *m2 = new QMenu ("Upload");
75
    ui->menuBar->addMenu(m2);
144 - 76
    m2->addAction("Load team information from external file", this, SLOT(loadExternalTeams()));
293 david 77
    m2->addAction("Load team information from Web Page", this, SLOT(loadExternalHtmlTeams()));
153 david 78
    m2->addAction("Upload time information", this, SLOT(uploadLegData()));
140 david 79
 
211 - 80
    QMenu *m3 = new QMenu ("Export");
156 - 81
    ui->menuBar->addMenu(m3);
211 - 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()));
221 - 89
 
90
    ui->menuBar->addAction("About", this, SLOT(showAbout()));
126 david 91
}
92
 
93
MainWindow::~MainWindow()
94
{
95
    delete ui;
96
}
97
 
133 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
 
203 - 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
 
126 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
{
127 - 128
    if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"),
131 david 129
                                    tr("This will reset the start times for all teams based on the Category configuration.\n"
126 david 130
                                       "Are you sure you want to do this?"),
131
                                    QMessageBox::Cancel,
132
                                    QMessageBox::Ok))
133
    {
127 - 134
        leg_start();
126 david 135
    }
127 - 136
 
126 david 137
}
138
 
127 - 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
 
128 - 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
 
302 david 175
void MainWindow::changeTeamNumber(void)
176
{
306 david 177
    QmDialogChangeTeamNumber dialog("Copy/Move/Swap Team Data",this);
302 david 178
    dialog.exec();
179
}
180
 
129 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
    {
133 david 188
        tm_clearleg_specified(leg, FALSE);
129 david 189
    }
190
}
191
 
192
void MainWindow::setCalcLegStart(void)
193
{
130 - 194
    QmDialogLegStartTimes dialog("Calculate Leg Start Time",this);
131 david 195
    dialog.setDeltaTimeLabel("Delta Time");
203 - 196
    dialog.setDescription("The start time is based on the end time of the previous leg with a constant Delta time added");
197
 
131 david 198
qDebug ("Must disable stuff");
130 - 199
    if ( QDialog::Accepted == dialog.exec() )
129 david 200
    {
130 - 201
        if ( dialog.getLeg() )
202
        {
203
            tm_lgs(dialog.getLeg(),
131 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");
203 - 216
    dialog.setDescription("The specified start time is given to the fastest team. Teams are then set at specified Delta from that time.");
131 david 217
    if ( QDialog::Accepted == dialog.exec() )
218
    {
219
        if ( dialog.getLeg() )
220
        {
221
            tm_lgs1(dialog.getLeg(),
130 - 222
                   dialog.getTime(),
131 david 223
                   dialog.getDeltaTime(),
130 - 224
                   dialog.getReport(),
225
                   dialog.getClear() );
226
        }
129 david 227
    }
131 david 228
}
130 - 229
 
131 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");
203 - 235
    dialog.setDescription("The lowest numbered team is given the start time. The teams are then starggered by team number from that time.");
131 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
    }
129 david 247
}
131 david 248
 
249
void MainWindow::setFixedLegStart(void)
250
{
251
    QmDialogLegStartTimes dialog("Fixed Leg Start Time",this);
252
    dialog.setTimeLabel("Start Time");
203 - 253
    dialog.setDescription("The specified start time is given to all teams.");
131 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
}
144 - 266
 
240 - 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
 
144 - 280
void MainWindow::loadExternalTeams(void)
281
{
145 - 282
    QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"),
174 - 283
                                                     filepath,
145 - 284
                                                     tr("Data (*.csv);;All (*.*)"),
285
                                                     0,
286
                                                     QFileDialog::ReadOnly);
287
    if ( fileName.isEmpty() )
288
    {
289
        return;
290
    }
291
 
292
    QmDialogLoadExternalTeams dialog(fileName,this);
144 - 293
    dialog.exec();
294
}
295
 
293 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
 
149 - 311
void MainWindow::storeExternalTeams(void)
312
{
313
    QString fileName = QFileDialog::getSaveFileName(this, tr("Store File"),
174 - 314
                                                     filepath,
149 - 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);
151 david 324
    MainWindow::showMessage("Writing external data completed");
149 - 325
}
326
 
152 david 327
void MainWindow::storeTeamInfo(void)
328
{
329
    QString fileName = QFileDialog::getSaveFileName(this, tr("Store Team Info File"),
174 - 330
                                                     filepath,
152 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
 
153 david 343
void MainWindow::storeLegData(void)
344
{
211 - 345
    QmDownloadLegTimes dialog(this);
346
    dialog.exec();
153 david 347
}
348
 
349
void MainWindow::uploadLegData(void)
350
{
351
    QmDialogUploadLegTimes  dialog(this);
352
    dialog.exec();
353
}
354
 
156 - 355
void MainWindow::generateReports(void)
356
{
357
    if( load_report_data() )
358
    {
359
        pri_all_reports();
360
    }
361
}
362
 
163 david 363
 
161 - 364
void MainWindow::displaySummary(void)
365
{
163 david 366
    QmDialogStatus dialog(this);
367
    dialog.exec();
161 - 368
}
369
 
221 - 370
void MainWindow::showAbout(void)
371
{
372
    QmDialogAbout dialog(this);
224 - 373
    dialog.setText(QString("Build Date: ") + __DATE__ + " " + __TIME__ + "\nVersion: " + VERSION);
259 - 374
    dialog.setPath(filepath);
221 - 375
    dialog.exec();
376
}
161 - 377
 
221 - 378