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