Subversion Repositories svn1

Rev

Rev 228 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 228 Rev 380
Line 1... Line 1...
1
#include "qmconfclass.h"
1
#include "qmconfclass.h"
2
#include "qmconfig.h"
2
#include "qmconfig.h"
-
 
3
#include <QtCore/QVariant>
-
 
4
#include <QtGui/QAction>
-
 
5
#include <QApplication>
3
#include "ui_qmconfclass.h"
6
#include <QButtonGroup>
-
 
7
#include <QGroupBox>
-
 
8
#include <QHeaderView>
-
 
9
#include <QPushButton>
-
 
10
#include <QTableWidget>
-
 
11
#include <QVBoxLayout>
-
 
12
#include <QWidget>
4
#include    "consts.h"
13
#include    "consts.h"
5
#include    "structs.h"
14
#include    "structs.h"
6
#include    "proto.h"
15
#include    "proto.h"
7
#include "mainwindow.h"
16
#include "mainwindow.h"
-
 
17
#include "qmTableWidgetItem.h"
8
 
18
 
-
 
19
#include <QDialogButtonBox>
9
#include "QTableWidgetItem"
20
#include "QTableWidgetItem"
10
#include "spinboxdelegate.h"
21
#include "spinboxdelegate.h"
11
#include "timedelegate.h"
22
#include "timedelegate.h"
12
#include "textdelegate.h"
23
#include "textdelegate.h"
13
#include <QMenu>
24
#include <QMenu>
Line 21... Line 32...
21
#define COL_ST_TOTAL 6
32
#define COL_ST_TOTAL 6
22
#define COL_ST_VALID 7
33
#define COL_ST_VALID 7
23
#define COL_ST_DISQ 8
34
#define COL_ST_DISQ 8
24
#define COL_ST_NONEQ 9
35
#define COL_ST_NONEQ 9
25
#define COL_ST_VET 10
36
#define COL_ST_VET 10
-
 
37
#define COL_ST_CEV 11
-
 
38
#define COL_ST_CNE 12
-
 
39
#define COL_INDEX 13
-
 
40
 
26
#define COL_COUNT 11
41
#define COL_COUNT 14
27
 
42
 
28
 
43
 
29
QmConfClass::QmConfClass(QWidget *parent) :
44
QmConfClass::QmConfClass(QWidget *parent) :
30
    QWidget(parent),
45
    QWidget(parent)
31
    ui(new Ui::QmConfClass)
-
 
32
{
46
{
33
    ui->setupUi(this);
-
 
34
    populating = false;
47
    populating = false;
35
    connect(ui->pushButtonSave, SIGNAL(clicked(bool)), this, SLOT(save()) );
48
    dirty = false;
36
    connect(ui->pushButtonRestore, SIGNAL(clicked(bool)), this, SLOT(cancel()) );
-
 
37
 
49
 
38
    QStringList labels;
50
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
39
    labels << "Abr" << "Full Name" << "Start Time" << "Winners" << "NE" << "NE Winners";
51
    verticalLayout->setContentsMargins(0, 0, 0, 0);
40
 
52
 
-
 
53
    QGroupBox *groupBox = new QGroupBox("Class");
-
 
54
    verticalLayout->addWidget(groupBox);
-
 
55
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
-
 
56
    tableWidget = new QTableWidget(groupBox);
-
 
57
    tableWidget->setAlternatingRowColors(true);
-
 
58
    tableWidget->setRowCount(config.num_class + 1);
-
 
59
    tableWidget->setColumnCount(COL_COUNT);
-
 
60
    tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
-
 
61
    tableWidget->horizontalHeader()->setVisible(true);
-
 
62
    tableWidget->horizontalHeader()->setDefaultSectionSize(70);
-
 
63
    tableWidget->horizontalHeader()->setHighlightSections(true);
-
 
64
    //tableWidget->horizontalHeader()->setStretchLastSection(true);
-
 
65
    tableWidget->verticalHeader()->setVisible(true);
-
 
66
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
-
 
67
    //tableWidget->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding );
-
 
68
    //tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-
 
69
    verticalLayout2->addWidget(tableWidget);
-
 
70
 
-
 
71
    //QSpacerItem *verticalSpacer1;
-
 
72
    //verticalSpacer1 = new QSpacerItem(0, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
-
 
73
    //verticalLayout2->addItem(verticalSpacer1);
-
 
74
 
-
 
75
    QHBoxLayout *horizontalLayout;
-
 
76
    horizontalLayout = new QHBoxLayout();
-
 
77
    horizontalLayout->setContentsMargins(0, 0, 5, 5);
-
 
78
    verticalLayout->addLayout(horizontalLayout);
-
 
79
 
-
 
80
    QDialogButtonBox *buttonBox = new QDialogButtonBox();
-
 
81
    pushButtonRestore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
-
 
82
    pushButtonSave = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
-
 
83
    horizontalLayout->addWidget(buttonBox);
41
 
84
 
42
    ui->tableWidget->setRowCount(config.num_class + 1);
-
 
43
    ui->tableWidget->setColumnCount(COL_COUNT);
-
 
44
    ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
-
 
45
    connect(ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
-
 
46
    connect(ui->tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int,int)));
-
 
47
 
85
 
-
 
86
    connect(pushButtonSave, SIGNAL(clicked(bool)), this, SLOT(save()) );
-
 
87
    connect(pushButtonRestore, SIGNAL(clicked(bool)), this, SLOT(cancel()) );
48
 
88
 
49
    /*
-
 
50
    **  Setup delegated for specialised editing
89
    QStringList labels;
51
    */
-
 
52
    ui->tableWidget->setItemDelegateForColumn(COL_ABR, new textDelegate(2));
-
 
53
    ui->tableWidget->setItemDelegateForColumn(COL_CLASS, new textDelegate(LEN_CLASS_NAME));
90
    labels << "Abr" << "Full Name" << "Start Time" << "Winners" << "NE" << "NE Winners";
54
    ui->tableWidget->setItemDelegateForColumn(COL_TIME, new timeDelegate());
-
 
55
    ui->tableWidget->setItemDelegateForColumn(COL_WINNERS, new SpinBoxDelegate(0,50));
-
 
56
    ui->tableWidget->setItemDelegateForColumn(COL_NE_WINNERS, new SpinBoxDelegate(0,50));
-
 
57
 
91
 
58
    populate();
92
    labels << "Total" << "Valid" <<"Disqual" << "NonEq" << "VetCheck" << "Comp Ev" << " Comp NE";
59
 
93
 
-
 
94
    labels << "Index";
60
 
95
 
61
    // Wire in the status button
-
 
62
    connect(ui->statusButton, SIGNAL(clicked()), this, SLOT(updateStatus()));
-
 
63
    statusShown = false;
-
 
64
    ui->tableWidget->setColumnHidden(COL_ST_TOTAL, true);
-
 
65
    ui->tableWidget->setColumnHidden(COL_ST_VALID, true);
-
 
66
    ui->tableWidget->setColumnHidden(COL_ST_DISQ, true);
-
 
67
    ui->tableWidget->setColumnHidden(COL_ST_NONEQ, true);
-
 
68
    ui->tableWidget->setColumnHidden(COL_ST_VET, true);
96
    tableWidget->setHorizontalHeaderLabels(labels);
69
 
97
 
-
 
98
    connect(tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
70
    labels << "Total" << "Valid" <<"Disqual" << "NonEq" << "VetCheck";
99
    connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int,int)));
71
 
100
 
-
 
101
    /*
-
 
102
    **  Setup delegated for specialised editing
-
 
103
    */
72
    ui->tableWidget->setHorizontalHeaderLabels(labels);
104
    tableWidget->setItemDelegateForColumn(COL_ABR, new textDelegate(2));
-
 
105
    tableWidget->setItemDelegateForColumn(COL_CLASS, new textDelegate(LEN_CLASS_NAME));
73
    ui->tableWidget->resizeColumnsToContents();
106
    tableWidget->setItemDelegateForColumn(COL_TIME, new timeDelegate());
-
 
107
    tableWidget->setItemDelegateForColumn(COL_WINNERS, new SpinBoxDelegate(0,50));
-
 
108
    tableWidget->setItemDelegateForColumn(COL_NE_WINNERS, new SpinBoxDelegate(0,50));
-
 
109
}
-
 
110
 
-
 
111
/*----------------------------------------------------------------------------
-
 
112
** FUNCTION           : showEvent 
-
 
113
**
-
 
114
** DESCRIPTION        : Called when the page is shown
-
 
115
**                      Used to refresh the contents of the display as well
-
 
116
**                      as show them for the first time
-
 
117
**
-
 
118
----------------------------------------------------------------------------*/
74
 
119
 
-
 
120
void QmConfClass::showEvent ( QShowEvent * event )
-
 
121
{
-
 
122
    //qDebug("populate::showEvent");
-
 
123
    if ( ! event->spontaneous() && !dirty )
-
 
124
    {
-
 
125
        populate();
-
 
126
    }
75
}
127
}
76
 
128
 
-
 
129
/*----------------------------------------------------------------------------
-
 
130
** FUNCTION           : populate
-
 
131
**
-
 
132
** DESCRIPTION        : Populate the display with information
-
 
133
**
-
 
134
----------------------------------------------------------------------------*/
-
 
135
 
77
void QmConfClass::populate(void)
136
void QmConfClass::populate(void)
78
{
137
{
-
 
138
    bool    reportDataLoaded = false;
-
 
139
    t_class_summary data;
-
 
140
 
79
    populating = true;
141
    populating = true;
-
 
142
    tableWidget->clearContents();
80
    ui->tableWidget->setRowCount(config.num_class + 1);
143
    tableWidget->setRowCount(0);
-
 
144
    tableWidget->setSortingEnabled(false);
-
 
145
 
-
 
146
    /*
81
    for ( int ii = 0; ii < MAX_CLASS; ii++)
147
    ** Load Report Data if we can
-
 
148
    */
-
 
149
    if( load_report_data() )
82
    {
150
    {
83
        ui->tableWidget->setItem(ii, COL_ABR, new QTableWidgetItem(config.team_class[ii].abr) );
151
        calc_class_summary( & data );
84
        ui->tableWidget->setItem(ii, COL_CLASS, new QTableWidgetItem(config.team_class[ii].full_name ));
152
        reportDataLoaded = true;
-
 
153
    }
85
 
154
 
-
 
155
    /*
-
 
156
    **  Add all the information
-
 
157
    */
-
 
158
    int ii = 0;
-
 
159
    int entryIndex = 0;
-
 
160
    for ( ii = 0; ii < MAX_CLASS; ii++)
-
 
161
    {
86
        if ( *config.team_class[ii].abr )
162
        if ( config.team_class[ii].abr[0] )
87
        {
163
        {
-
 
164
            // Keep the config item index entry
-
 
165
            //  Will need it when we write stiff out
-
 
166
            tableWidget->setRowCount(tableWidget->rowCount() + 1);
-
 
167
 
-
 
168
            tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(ii));
-
 
169
 
-
 
170
            tableWidget->setItem(entryIndex, COL_ABR,        new qmTwiEditString(config.team_class[ii].abr ));
-
 
171
            tableWidget->setItem(entryIndex, COL_CLASS,      new qmTwiEditString(config.team_class[ii].full_name ));
-
 
172
 
88
            QTableWidgetItem *item;
173
            QTableWidgetItem *item;
89
            item = new QTableWidgetItem();
174
            item = new QTableWidgetItem();
90
            item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
175
            item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
91
            ui->tableWidget->setItem(ii, COL_TIME, item);
176
            tableWidget->setItem(entryIndex, COL_TIME, item);
92
 
177
 
93
            item = new QTableWidgetItem();
-
 
94
            item->setData(Qt::EditRole,config.class_winners[ii] );
178
            tableWidget->setItem(entryIndex, COL_WINNERS,    new qmTwiEditNumber(config.class_winners[ii]));
95
            ui->tableWidget->setItem(ii, COL_WINNERS, item);
-
 
96
 
-
 
97
            item = new QTableWidgetItem();
-
 
98
            item->setCheckState(config.nonequestrian_class == 1 + ii ? Qt::Checked : Qt::Unchecked);
179
            tableWidget->setItem(entryIndex, COL_NE,         new qmTwiEditFlag("",config.nonequestrian_class == 1 + ii));
99
            ui->tableWidget->setItem(ii, COL_NE, item);
180
            tableWidget->setItem(entryIndex, COL_NE_WINNERS, new qmTwiEditNumber(config.class_ne_winners[ii]));
100
 
181
 
101
            item = new QTableWidgetItem();
182
            if (reportDataLoaded)
-
 
183
            {
102
            item->setData(Qt::EditRole,config.class_ne_winners[ii] );
184
                tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.teamclass[ii+1].total) );
103
            ui->tableWidget->setItem(ii, COL_NE_WINNERS, item);
185
                tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.teamclass[ii+1].valid) );
-
 
186
                tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.teamclass[ii+1].disqualified));
-
 
187
                tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.teamclass[ii+1].non_equestrian));
-
 
188
                tableWidget->setItem(entryIndex,COL_ST_VET,   new qmTwiNumber(data.teamclass[ii+1].vet_check));
-
 
189
                tableWidget->setItem(entryIndex,COL_ST_CEV,   new qmTwiNumber(data.teamclass[ii+1].valid_ev));
-
 
190
                tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.teamclass[ii+1].valid_ne));
-
 
191
            }
-
 
192
            entryIndex++;
104
        }
193
        }
105
    }
194
    }
-
 
195
 
-
 
196
    //  Insert Totals
-
 
197
    //      Flag that items on this this row is not to be sorted - or at least 
-
 
198
    //      sorted at the end
-
 
199
    //
-
 
200
    if (reportDataLoaded)
-
 
201
    {
-
 
202
        tableWidget->setRowCount(tableWidget->rowCount() + 1);
-
 
203
        tableWidget->setItem(entryIndex,COL_ABR,      new qmTwiString("Totals", 1));
-
 
204
 
-
 
205
        tableWidget->setItem(entryIndex, COL_CLASS,         new qmTwiString("",1));
-
 
206
        tableWidget->setItem(entryIndex, COL_TIME,          new qmTwiString("",1));
-
 
207
        tableWidget->setItem(entryIndex, COL_WINNERS,       new qmTwiString("",1));
-
 
208
        tableWidget->setItem(entryIndex, COL_NE,            new qmTwiString("",1));
-
 
209
        tableWidget->setItem(entryIndex, COL_NE_WINNERS,    new qmTwiString("",1));
-
 
210
        tableWidget->setItem(entryIndex, COL_INDEX,         new qmTwiString("",1));
-
 
211
 
-
 
212
        tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.total.total, 1));
-
 
213
        tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.total.valid, 1));
-
 
214
        tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.total.disqualified, 1));
-
 
215
        tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.total.non_equestrian, 1));
-
 
216
        tableWidget->setItem(entryIndex,COL_ST_VET,   new qmTwiNumber(data.total.vet_check, 1));
-
 
217
        tableWidget->setItem(entryIndex,COL_ST_CEV,   new qmTwiNumber(data.total.valid_ev, 1));
-
 
218
        tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.total.valid_ne, 1));
-
 
219
 
-
 
220
        // Debug
-
 
221
        // tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(5,2));
-
 
222
 
-
 
223
    }
-
 
224
 
-
 
225
    checkNeClass();
-
 
226
 
-
 
227
    tableWidget->sortByColumn ( COL_INDEX, Qt::AscendingOrder );
-
 
228
    tableWidget->setSortingEnabled(true);
-
 
229
    tableWidget->resizeColumnsToContents();
-
 
230
    tableWidget->resizeRowsToContents();
-
 
231
 
106
    updateChanged(false);
232
    updateChanged(false);
107
    populating = false;
233
    populating = false;
108
}
234
}
109
 
235
 
-
 
236
void QmConfClass::checkNeClass(void)
-
 
237
{
-
 
238
    QString tip = "Unexpected value. The NE winners are configured on a per-class basis";
-
 
239
 
-
 
240
    for ( int ii = 0; ii < MAX_CLASS; ii++)
-
 
241
    {
-
 
242
        int indexEntry = 0;
-
 
243
        QTableWidgetItem *item = tableWidget->item ( ii, COL_INDEX );
-
 
244
        const QBrush *goldBrush = new QBrush(QColor(255,204,203));
-
 
245
 
-
 
246
        if (!item)
-
 
247
        {
-
 
248
            //qDebug("Ignore row:%d", entryIndex);
-
 
249
            continue;
-
 
250
        }
-
 
251
        if ( item->text().length() == 0)
-
 
252
        {
-
 
253
            //qDebug("Ignore empty row:%d", entryIndex);
-
 
254
            continue;
-
 
255
        }
-
 
256
 
-
 
257
        indexEntry = item->text().toInt();
-
 
258
        //qDebug("Processing: %d", ii);
-
 
259
 
-
 
260
        item = tableWidget->item( ii, COL_NE );
-
 
261
        if ( item )
-
 
262
        {
-
 
263
            if ( item->checkState() == Qt::Checked) {
-
 
264
 
-
 
265
                item = tableWidget->item( ii, COL_WINNERS );
-
 
266
                if (item && item->text().length() && item->text().toInt() ) {
-
 
267
                    tableWidget->item(ii,COL_WINNERS)->setBackground(*goldBrush);
-
 
268
                    tableWidget->item(ii,COL_WINNERS)->setToolTip(tip);
-
 
269
                    MainWindow::showMessage(tip);
-
 
270
                } else {
-
 
271
                    tableWidget->item(ii,COL_WINNERS)->setBackground(Qt::transparent);
-
 
272
                    tableWidget->item(ii,COL_WINNERS)->setToolTip("");
-
 
273
 
-
 
274
                }
-
 
275
 
-
 
276
                item = tableWidget->item( ii, COL_NE_WINNERS );
-
 
277
                if (item && item->text().length() && item->text().toInt() ) {
-
 
278
                    tableWidget->item(ii,COL_NE_WINNERS)->setBackground(*goldBrush);
-
 
279
                    tableWidget->item(ii,COL_NE_WINNERS)->setToolTip(tip);
-
 
280
                    MainWindow::showMessage(tip);
-
 
281
 
-
 
282
                } else {
-
 
283
                    tableWidget->item(ii,COL_NE_WINNERS)->setBackground(Qt::transparent);
-
 
284
                    tableWidget->item(ii,COL_NE_WINNERS)->setToolTip("");
-
 
285
 
-
 
286
                }
-
 
287
 
-
 
288
            } else {
-
 
289
                tableWidget->item(ii,COL_WINNERS)->setBackground(Qt::transparent);
-
 
290
                tableWidget->item(ii,COL_WINNERS)->setToolTip("");
-
 
291
 
-
 
292
                tableWidget->item(ii,COL_NE_WINNERS)->setBackground(Qt::transparent);
-
 
293
                tableWidget->item(ii,COL_NE_WINNERS)->setToolTip("");
-
 
294
 
-
 
295
            }
-
 
296
        }
-
 
297
    }
-
 
298
}
-
 
299
 
110
void QmConfClass::save(void)
300
void QmConfClass::save(void)
111
{
301
{
112
    /*
302
    /*
113
    **    Copy original data
303
    **    Copy original data
114
    */
304
    */
115
    QmConfig newcfg(config);
305
    QmConfig newcfg(config);
116
 
306
 
117
    /*
307
    /*
118
    **  Extract the data from the Widgets
308
    **  Extract the data from the Widgets
-
 
309
    **  Trap: The Class info is cross ref by index into the table
-
 
310
    **        Thus we need to maintain the order in the config.
119
    */
311
    */
120
    for ( int ii = 0; ii < MAX_CLASS; ii++)
312
    for (int entryIndex = 0; entryIndex < tableWidget->rowCount(); entryIndex++)
121
    {
313
    {
-
 
314
 
-
 
315
        // Check that this is a real Entry or the 'Totals' header
-
 
316
        //      Real rows have a COL_INDEX entry that is not empty
-
 
317
        //
122
        QTableWidgetItem *item = ui->tableWidget->item ( ii, COL_ABR );
318
        QTableWidgetItem *item = tableWidget->item ( entryIndex, COL_INDEX );
-
 
319
        if (! item)
-
 
320
        {
-
 
321
            //qDebug("Ignore row:%d", entryIndex);
-
 
322
            continue;
-
 
323
        }
-
 
324
        if ( item->text().length() == 0)
-
 
325
        {
-
 
326
            //qDebug("Ignore empty row:%d", entryIndex);
-
 
327
            continue;
-
 
328
        }
-
 
329
        int ii = item->text().toInt();
-
 
330
        //qDebug("Processing: %d", ii);
-
 
331
 
-
 
332
        /*
-
 
333
        ** This is a new entry - allocate a new index 
-
 
334
        **  Scan the entire available space looking for the first empty slot
-
 
335
        */
-
 
336
        if (ii < 0)
-
 
337
        {
-
 
338
            for (ii = 0; ii < MAX_CLASS ; ii++)
-
 
339
            {
-
 
340
                if (newcfg.team_class[ii].abr[0] == 0)
-
 
341
                {
-
 
342
                    break;
-
 
343
                }
-
 
344
            }
-
 
345
        }
-
 
346
 
-
 
347
        if (ii >= MAX_CLASS )
-
 
348
        {
-
 
349
            qDebug("Ignore row:%d. Class out of range", entryIndex);
-
 
350
            continue;
-
 
351
        }
-
 
352
 
-
 
353
        item = tableWidget->item ( entryIndex, COL_ABR );
123
        if ( item )
354
        if ( item )
124
        {
355
        {
125
            strncpy(newcfg.team_class[ii].abr, qPrintable(item->text()), sizeof(newcfg.team_class[ii].abr)-1);
356
            strncpy(newcfg.team_class[ii].abr, qPrintable(item->text()), sizeof(newcfg.team_class[ii].abr)-1);
126
        }
357
        }
127
        else
358
        else
128
        {
359
        {
129
            *newcfg.team_class[ii].abr = 0;
360
            *newcfg.team_class[ii].abr = 0;
130
        }
361
        }
131
 
362
 
132
        item = ui->tableWidget->item ( ii, COL_CLASS );
363
        item = tableWidget->item ( entryIndex, COL_CLASS );
133
        if ( item )
364
        if ( item )
134
        {
365
        {
135
            strncpy(newcfg.team_class[ii].full_name, qPrintable(item->text()), sizeof(newcfg.team_class[ii].full_name)-1);
366
            strncpy(newcfg.team_class[ii].full_name, qPrintable(item->text()), sizeof(newcfg.team_class[ii].full_name)-1);
136
        }
367
        }
137
        else
368
        else
138
        {
369
        {
139
            *newcfg.team_class[ii].full_name = 0;
370
            *newcfg.team_class[ii].full_name = 0;
140
        }
371
        }
141
 
372
 
142
        item = ui->tableWidget->item( ii, COL_TIME );
373
        item = tableWidget->item( entryIndex, COL_TIME );
143
        if ( item )
374
        if ( item )
144
        {
375
        {
145
            QVariant data = item->data(Qt::EditRole);
376
            QVariant data = item->data(Qt::EditRole);
146
            if (data.isValid())
377
            if (data.isValid())
147
            {
378
            {
Line 155... Line 386...
155
        else
386
        else
156
        {
387
        {
157
            newcfg.team_class[ii].start = -1;
388
            newcfg.team_class[ii].start = -1;
158
        }
389
        }
159
 
390
 
160
        item = ui->tableWidget->item( ii, COL_WINNERS );
391
        item = tableWidget->item( entryIndex, COL_WINNERS );
161
        if ( item )
392
        if ( item )
162
        {
393
        {
163
            newcfg.class_winners[ii] = item->data(Qt::EditRole).toInt();
394
            newcfg.class_winners[ii] = item->data(Qt::EditRole).toInt();
164
        }
395
        }
165
        else
396
        else
166
        {
397
        {
167
            newcfg.class_winners[ii] = 0;
398
            newcfg.class_winners[ii] = 0;
168
        }
399
        }
169
 
400
 
170
        item = ui->tableWidget->item( ii, COL_NE );
401
        item = tableWidget->item( entryIndex, COL_NE );
171
        if ( item )
402
        if ( item )
172
        {
403
        {
173
            if ( item->checkState() == Qt::Checked)
404
            if ( item->checkState() == Qt::Checked)
174
            {
405
            {
175
                newcfg.nonequestrian_class = ii;
406
                newcfg.nonequestrian_class = ii;
176
                strncpy(newcfg.nonequestrian_class_abr, newcfg.team_class[ii].abr, sizeof(newcfg.team_class[ii].abr)-1);
407
                strncpy(newcfg.nonequestrian_class_abr, newcfg.team_class[ii].abr, sizeof(newcfg.team_class[ii].abr)-1);
177
            }
408
            }
178
        }
409
        }
179
 
410
 
180
        item = ui->tableWidget->item( ii, COL_NE_WINNERS );
411
        item = tableWidget->item( entryIndex, COL_NE_WINNERS );
181
        if ( item )
412
        if ( item )
182
        {
413
        {
183
            newcfg.class_ne_winners[ii] = item->data(Qt::EditRole).toInt();
414
            newcfg.class_ne_winners[ii] = item->data(Qt::EditRole).toInt();
184
        }
415
        }
185
        else
416
        else
Line 215... Line 446...
215
                throw( "Configuration error. Bad start time on class" );
446
                throw( "Configuration error. Bad start time on class" );
216
 
447
 
217
            }
448
            }
218
        }
449
        }
219
 
450
 
220
        newcfg.num_class = 0;
451
        //  Calculate new max number of classes
-
 
452
        //      Scan from the end looking for the last one used
-
 
453
        //
221
        for( int i = 0; i < MAX_CLASS; i++ )
454
        for (int i = MAX_CLASS-1; i >= 0; i--)
-
 
455
        {
222
            if( newcfg.team_class[i].full_name[0] )
456
            if (newcfg.team_class[i].abr[0])
-
 
457
            {
-
 
458
                //qDebug("num_class:%d -> %d", newcfg.num_class, 1+i);
223
                newcfg.num_class++;
459
                newcfg.num_class = 1 + i;
-
 
460
                break;
-
 
461
            }
-
 
462
        }
224
 
463
 
225
        for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
464
        for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
226
            if( newcfg.team_class[i].full_name[0] )
465
            if( newcfg.team_class[i].full_name[0] )
227
            {
466
            {
228
                throw( "Configuration error: Missing Class name. Gaps not allowed" );
467
                qDebug( "Configuration error: Missing Class name. Gaps not allowed" );
229
 
-
 
230
            }
468
            }
231
 
469
 
232
        if( newcfg.num_class == 0 )
470
        if( newcfg.num_class == 0 )
233
        {
471
        {
234
            throw( "Error: No categories defined" );
472
            throw( "Error: No categories defined" );
235
 
473
 
236
        }
474
        }
237
 
475
 
-
 
476
        /*
-
 
477
        ** Test for duplicate abbreviations 
-
 
478
        ** I know its a slow agorithm, but its only a small set 
-
 
479
        */
-
 
480
        for( int i = 0; i < MAX_CLASS; i++ )
-
 
481
        {
-
 
482
            if (newcfg.team_class[i].abr[0] != '\0')
-
 
483
            {
-
 
484
                for (int j = i+1; j < MAX_CLASS; j++)
-
 
485
                {
-
 
486
                    if (newcfg.team_class[j].abr[0] != '\0')
-
 
487
                    {
-
 
488
                        if (    newcfg.team_class[i].abr[0] == newcfg.team_class[j].abr[0]
-
 
489
                             && newcfg.team_class[i].abr[1] == newcfg.team_class[j].abr[1]
-
 
490
                            )
-
 
491
                        {
-
 
492
                            qDebug("Duplicate abr: %s", newcfg.team_class[i].abr);
-
 
493
                            throw( "Error: Duplicate abbreviations detected");
-
 
494
                        }
-
 
495
                    }
-
 
496
                }
-
 
497
            }
-
 
498
        }
-
 
499
 
-
 
500
        /*
-
 
501
        ** Sanity Test
-
 
502
        */
238
        newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
503
        newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
239
        if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
504
        if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
240
            MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
505
            MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
241
 
-
 
-
 
506
        //qDebug("NE Index is: %d", newcfg.nonequestrian_class );
242
        /*
507
        /*
243
        **  Sanity test of the data
508
        **  Sanity test of the data
244
        */
509
        */
245
        for( int i = 0; i < MAX_CLASS; i++ )
510
        for( int i = 0; i < MAX_CLASS; i++ )
246
        {
511
        {
247
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
512
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
248
            {
513
            {
249
 
-
 
-
 
514
                if (newcfg.nonequestrian_class != i+1)
-
 
515
                {
250
                MainWindow::showMessage( QString("Warning: Class without winners:") + newcfg.team_class[i].abr );
516
                    MainWindow::showMessage(QString("Warning: Class without winners:")+ newcfg.team_class[i].abr); 
-
 
517
                }
251
            }
518
            }
252
        }
519
        }
253
 
520
 
254
        /*
521
        /*
255
        ** Cannot mix winners for NE class and NE Winners for each class
522
        ** Cannot mix winners for NE class and NE Winners for each class
Line 275... Line 542...
275
 
542
 
276
        config = newcfg;
543
        config = newcfg;
277
        config.write_config();
544
        config.write_config();
278
        updateChanged(false);
545
        updateChanged(false);
279
 
546
 
-
 
547
        // Force re-populate so that the index field is now correct
-
 
548
        populate();
-
 
549
 
-
 
550
 
280
    }
551
    }
281
    catch (const char * str )
552
    catch (const char * str )
282
    {
553
    {
283
        MainWindow::showMessage(str);
554
        MainWindow::showMessage(str);
284
    }
555
    }
Line 290... Line 561...
290
    populate();
561
    populate();
291
}
562
}
292
 
563
 
293
QmConfClass::~QmConfClass()
564
QmConfClass::~QmConfClass()
294
{
565
{
295
    delete ui;
566
 
296
}
567
}
297
 
568
 
298
void QmConfClass::ctxMenu(const QPoint & pos)
569
void QmConfClass::ctxMenu(const QPoint & pos)
299
{
570
{
300
    qDebug("Context Menu");
571
    //qDebug("Context Menu");
301
    QMenu *menu = new QMenu;
572
    QMenu *menu = new QMenu;
302
    QTableWidgetItem *item = ui->tableWidget->itemAt(pos);
-
 
303
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
573
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
-
 
574
 
-
 
575
    /*
-
 
576
    **      Determine if we can delete an item
-
 
577
    **          Can delete a category we added in this session
-
 
578
    **          Can delete one if it has no teams using it.
-
 
579
    */
-
 
580
    QTableWidgetItem *item = tableWidget->itemAt(pos);
304
    if (item)
581
    if (item)
305
    {
582
    {
-
 
583
        int row = item->row();
-
 
584
        //qDebug("Item is at row:%d", row);
-
 
585
        QTableWidgetItem *indexItem = tableWidget->item ( row, COL_INDEX );
-
 
586
        if (indexItem)
-
 
587
        {
-
 
588
            int index = indexItem->text().toInt();
-
 
589
            //qDebug("Item is at row:%d, Index: %d", row, index);
-
 
590
            if (index < 0)
-
 
591
            {
306
        menu->addAction(tr("Delete Category"), this, SLOT(ctxMenuDeleteRow()));
592
                menu->addAction(tr("Delete Newly added Category"), this, SLOT(ctxMenuDeleteRow())); 
307
    }
593
            }
-
 
594
            else
-
 
595
            {
-
 
596
                QTableWidgetItem *itemTotalCount = tableWidget->item ( row, COL_ST_TOTAL );
308
   menu->exec(ui->tableWidget->mapToGlobal(pos));
597
                if (itemTotalCount)
-
 
598
                {
-
 
599
                    int count = itemTotalCount->text().toInt();
-
 
600
                    if (count == 0)
-
 
601
                    {
-
 
602
                        menu->addAction(tr("Delete Category - its not used"), this, SLOT(ctxMenuDeleteRow()));  
-
 
603
                    }
-
 
604
                }
309
 
605
 
-
 
606
            }
-
 
607
        }
-
 
608
    }
-
 
609
    menu->exec(tableWidget->mapToGlobal(pos));
310
}
610
}
311
 
611
 
312
void QmConfClass::ctxMenuDeleteRow(void)
612
void QmConfClass::ctxMenuDeleteRow(void)
313
{
613
{
-
 
614
    //
-
 
615
    //  Assume that if the menu was shown, then we can delete it
-
 
616
    // 
314
    //qDebug ("DELETE ROW: %d", ui->tableWidget->currentRow () );
617
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
-
 
618
    //tableWidget->removeCellWidget(tableWidget->currentRow (), COL_ABR);
315
    ui->tableWidget->removeRow(ui->tableWidget->currentRow ());
619
    //tableWidget->removeRow(tableWidget->currentRow ());
-
 
620
    tableWidget->item(tableWidget->currentRow (), COL_ABR)->setText("");
-
 
621
    tableWidget->item(tableWidget->currentRow (), COL_CLASS)->setText("");
-
 
622
    tableWidget->hideRow(tableWidget->currentRow ());
316
    updateChanged(true);
623
    updateChanged(true);
317
}
624
}
318
 
625
 
319
void QmConfClass::ctxMenuAddRow(void)
626
void QmConfClass::ctxMenuAddRow(void)
320
{
627
{
-
 
628
    tableWidget->setSortingEnabled(false);
321
    ui->tableWidget->setRowCount( 1+ ui->tableWidget->rowCount());
629
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
322
}
-
 
323
 
630
 
-
 
631
    /*
324
void QmConfClass::updateStatus(void)
632
    **  Insert non-editable fields in the status part of the table
325
{
633
    */
326
    populating = true;
634
    tableWidget->setItem(tableWidget->rowCount() - 1, COL_INDEX, new qmTwiNumber(-1));
327
    if (!statusShown)
635
    for (int ii= COL_ST_TOTAL; ii < COL_INDEX; ii++)
328
    {
636
    {
329
        ui->tableWidget->setColumnHidden(COL_ST_TOTAL, false);
-
 
330
        ui->tableWidget->setColumnHidden(COL_ST_VALID, false);
-
 
331
        ui->tableWidget->setColumnHidden(COL_ST_DISQ, false);
637
        tableWidget->setItem(tableWidget->rowCount() - 1, ii, new qmTwiString(""));
332
        ui->tableWidget->setColumnHidden(COL_ST_NONEQ, false);
-
 
333
        ui->tableWidget->setColumnHidden(COL_ST_VET, false);
-
 
334
        statusShown = true;
-
 
335
    }
638
    }
336
 
-
 
337
    if( load_report_data() )
-
 
338
    {
-
 
339
        t_class_summary data;
-
 
340
        calc_class_summary( & data );
-
 
341
 
-
 
342
        // Insert summary data
-
 
343
        int ii;
-
 
344
        for (ii = 0; ii < config.num_class; ii++)
-
 
345
        {
-
 
346
            QTableWidgetItem *item;
-
 
347
            item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].total));
-
 
348
            item->setFlags(Qt::NoItemFlags);
-
 
349
            ui->tableWidget->setItem(ii,COL_ST_TOTAL, item );
-
 
350
 
-
 
351
            item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].valid));
-
 
352
            item->setFlags(Qt::NoItemFlags);
-
 
353
            ui->tableWidget->setItem(ii,COL_ST_VALID, item );
-
 
354
 
-
 
355
            item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].disqualified)) ;
-
 
356
            item->setFlags(Qt::NoItemFlags);
-
 
357
            ui->tableWidget->setItem(ii,COL_ST_DISQ, item);
-
 
358
 
-
 
359
            item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].non_equestrian));
-
 
360
            item->setFlags(Qt::NoItemFlags);
-
 
361
            ui->tableWidget->setItem(ii,COL_ST_NONEQ, item);
-
 
362
 
-
 
363
            item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].vet_check));
-
 
364
            item->setFlags(Qt::NoItemFlags);
-
 
365
            ui->tableWidget->setItem(ii,COL_ST_VET, item);
-
 
366
        }
-
 
367
 
-
 
368
        ui->tableWidget->resizeColumnsToContents();
-
 
369
        ui->tableWidget->resizeRowsToContents();
-
 
370
    }
-
 
371
    populating = false;
-
 
372
}
639
}
373
 
640
 
374
void QmConfClass::cellChanged(int row,int col)
641
void QmConfClass::cellChanged(int row,int col)
375
{
642
{
376
    if ( populating )
643
    if ( populating )
377
        return;
644
        return;
-
 
645
    if (col == COL_INDEX)
-
 
646
        return;
-
 
647
 
378
    updateChanged(true);
648
    updateChanged(true); 
379
    populating = true;
649
    populating = true;
380
    //qDebug("Cell changed: %d, %d", row, col);
650
    //qDebug("Cell changed: %d, %d", row, col);
381
    if (col == COL_NE)
651
    if (col == COL_NE)
382
    {
652
    {
383
        for (int ii = 0; ii < ui->tableWidget->rowCount(); ii++)
653
        for (int ii = 0; ii < tableWidget->rowCount(); ii++)
384
        {
654
        {
385
            QTableWidgetItem *item = ui->tableWidget->item(ii, COL_NE);
655
            QTableWidgetItem *item = tableWidget->item(ii, COL_NE);
386
            if (item)
656
            if (item)
387
            {
657
            {
388
                item->setCheckState(ii == row ? Qt::Checked : Qt::Unchecked);
658
                item->setCheckState(ii == row ? Qt::Checked : Qt::Unchecked);
389
            }
659
            }
390
        }
660
        }
391
    }
661
    }
-
 
662
 
-
 
663
    // Highlight wonky config
-
 
664
    if (col == COL_NE || col == COL_NE_WINNERS || col == COL_WINNERS) {
-
 
665
        checkNeClass();
-
 
666
    }
-
 
667
 
392
    populating = false;
668
    populating = false;
393
}
669
}
394
 
670
 
395
void QmConfClass::updateChanged(bool newDirty)
671
void QmConfClass::updateChanged(bool newDirty)
396
{
672
{
397
    if (newDirty != dirty)
673
    if (newDirty != dirty)
398
    {
674
    {
399
        dirty = newDirty;
675
        dirty = newDirty;
400
        if (dirty)
676
        if (dirty)
401
        {
677
        {
402
            ui->pushButtonSave->setEnabled(true);
678
            pushButtonSave->setEnabled(true);
403
            ui->pushButtonSave->setStyleSheet("background-color: rgb(255, 0, 0);");
679
            pushButtonSave->setStyleSheet("background-color: rgb(255, 0, 0);");
404
        }
680
        }
405
        else
681
        else
406
        {
682
        {
407
            ui->pushButtonSave->setEnabled(false);
683
            pushButtonSave->setEnabled(false);
408
            ui->pushButtonSave->setStyleSheet("");
684
            pushButtonSave->setStyleSheet("");
409
        }
685
        }
410
    }
686
    }
411
}
687
}
412
 
688
 
413
void QmConfClass::changeEvent(QEvent *e)
689
void QmConfClass::changeEvent(QEvent *e)
414
{
690
{
415
    QWidget::changeEvent(e);
691
    QWidget::changeEvent(e);
416
    switch (e->type()) {
692
    switch (e->type()) {
417
    case QEvent::LanguageChange:
-
 
418
        ui->retranslateUi(this);
-
 
419
        break;
693
 
420
    default:
694
    default:
421
        break;
695
        break;
422
    }
696
    }
423
}
697
}