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