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