Subversion Repositories svn1

Rev

Go to most recent revision | Details | 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"
168 david 16
#include "qmreportwindow.h"
169 david 17
#include "QTabWidget"
18
#include "QLayout"
188 - 19
#include "qmeventstatus.h"
211 - 20
#include "qmdownloadlegtimes.h"
221 - 21
#include "qmdialogabout.h"
380 david 22
#include "qmhttppath.h"
23
#include "qmdialogchangeteamnumber.h"
24
#include "qmfulldata.h"
126 david 25
 
26
#include    "consts.h"
27
#include    "structs.h"
28
#include    "proto.h"
29
 
30
MainWindow *mw = NULL;
380 david 31
bool MainWindow::shutDown = false;
126 david 32
 
33
MainWindow::MainWindow(QWidget *parent) :
34
    QMainWindow(parent),
35
    ui(new Ui::MainWindow)
36
{
37
    ui->setupUi(this);
38
    mw = this;
380 david 39
    setWindowTitle("Mara");
126 david 40
 
380 david 41
    tabWidget = new QTabWidget();
169 david 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");
380 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()));
380 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()));
380 david 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()));
380 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()));
380 david 83
    //m3->addAction("Store basic team info to external file", this, SLOT(storeTeamInfo()));
211 - 84
    m3->addAction("Create external leg data file", this, SLOT(storeLegData()));
85
 
86
    QMenu *m4 = new QMenu ("Reports");
87
    ui->menuBar->addMenu(m4);
88
    m4->addAction("Generate All Reports", this, SLOT(generateReports()));
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
 
380 david 175
void MainWindow::changeTeamNumber(void)
176
{
177
    QmDialogChangeTeamNumber dialog("Copy/Move/Swap Team Data",this);
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
 
380 david 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
{
380 david 282
    QString fileName = QFileDialog::getOpenFileName(
283
            this, tr("Load File"),
284
            appSettings->value("Recent/ExternalTeams",filepath).toString(),
285
            tr("Data (*.csv);;All (*.*)"),
286
            0,
287
            QFileDialog::ReadOnly);
288
 
145 - 289
    if ( fileName.isEmpty() )
290
    {
291
        return;
292
    }
380 david 293
    appSettings->setValue("Recent/ExternalTeams", fileName); 
145 - 294
 
295
    QmDialogLoadExternalTeams dialog(fileName,this);
144 - 296
    dialog.exec();
297
}
298
 
380 david 299
void MainWindow::loadExternalHtmlTeams(void)
300
{
301
    Qmhttppath msgBox;
302
    int rv = msgBox.exec();
303
    if (rv == QDialog::Accepted)
304
    {
305
        QmDialogLoadExternalTeams dialog( msgBox.urlLineEdit->text(), &msgBox.allData ,this);
306
        dialog.exec();
307
    }
308
    else
309
    {
310
         MainWindow::showMessage("No Web Address selected. No teams uploaded");
311
    }
312
}
313
 
149 - 314
void MainWindow::storeExternalTeams(void)
315
{
380 david 316
    QString fileName = QFileDialog::getSaveFileName(
317
            this, tr("Store File"),
318
            appSettings->value("Recent/storeExternalTeams",filepath).toString(),
319
            tr("Data (*.csv);;All (*.*)"),
320
 
321
            );
149 - 322
    if ( fileName.isEmpty() )
323
    {
324
        return;
325
    }
380 david 326
    appSettings->setValue("Recent/storeExternalTeams", fileName); 
149 - 327
    MainWindow::showMessage("Writing external data");
328
    QmDialogLoadExternalTeams::storeData(fileName);
151 david 329
    MainWindow::showMessage("Writing external data completed");
149 - 330
}
331
 
152 david 332
void MainWindow::storeTeamInfo(void)
333
{
380 david 334
    QString fileName = QFileDialog::getSaveFileName(
335
            this, tr("Store Team Info File"),
336
            appSettings->value("Recent/storeTeamInfo",filepath).toString(),
337
            tr("Data (*.txt);;All (*.*)"),
338
 
339
            );
152 david 340
    if ( fileName.isEmpty() )
341
    {
342
        return;
343
    }
380 david 344
    appSettings->setValue("Recent/storeTeamInfo", fileName); 
152 david 345
    MainWindow::showMessage("Writing team info");
346
    QmDialogLoadExternalTeams::storeTeamInfo(fileName);
347
    MainWindow::showMessage("Writing team info completed");
348
}
349
 
153 david 350
void MainWindow::storeLegData(void)
351
{
211 - 352
    QmDownloadLegTimes dialog(this);
353
    dialog.exec();
153 david 354
}
355
 
356
void MainWindow::uploadLegData(void)
357
{
358
    QmDialogUploadLegTimes  dialog(this);
359
    dialog.exec();
360
}
361
 
156 - 362
void MainWindow::generateReports(void)
363
{
364
    if( load_report_data() )
365
    {
366
        pri_all_reports();
367
    }
368
}
369
 
221 - 370
void MainWindow::showAbout(void)
371
{
372
    QmDialogAbout dialog(this);
224 - 373
    dialog.setText(QString("Build Date: ") + __DATE__ + " " + __TIME__ + "\nVersion: " + VERSION);
380 david 374
    dialog.setPath(filepath);
221 - 375
    dialog.exec();
376
}
161 - 377
 
380 david 378
void MainWindow::disableAllMenus(QMenu *menu)
379
{
380
    if (menu) {
381
        foreach (QAction *action, menu->actions() ) {
382
            if (action->isSeparator()) {
383
            } else if (action->menu()) {
384
                //qDebug(">>> this action is associated with a submenu, iterating it recursively...");
385
                mw->disableAllMenus(action->menu());
386
            } else {
387
                action->setDisabled(true);
388
            }
389
        }
390
    }
391
}
221 - 392
 
380 david 393
void MainWindow::disableAllTabs(void)
394
{
395
    MainWindow::showMessage ("Number of legs has changed - Restart application");
396
    shutDown = true;
397
 
398
    for(int ii = 0; ii < mw->tabWidget->count() ; ii++) {
399
        mw->tabWidget->setTabEnabled(ii, false);
400
    }
401
 
402
    foreach (QAction *action, mw->ui->menuBar->actions() ) {
403
        mw->disableAllMenus(action->menu());
404
    }
405
 
406
}
407
 
408
 
409