Subversion Repositories svn1

Rev

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