Subversion Repositories svn1-original

Rev

Rev 240 | Rev 277 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
138 david 1
#include "qmdisqualified.h"
276 david 2
#include "consts.h"
3
#include "structs.h"
4
#include "proto.h"
194 - 5
#include <QHeaderView>
276 david 6
#include <QLabel>
7
#include <QGroupBox>
8
#include "mainwindow.h"
138 david 9
 
10
qmDisqualified::qmDisqualified(QWidget *parent) :
194 - 11
    QWidget(parent)
12
 
138 david 13
{
195 david 14
    inPopulate = false;
15
    dirty = true;
194 - 16
    resize ( 600,400);
138 david 17
 
194 - 18
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
19
    verticalLayout->setContentsMargins(0, 0, 0, 0);
20
 
21
    QGroupBox *groupBox = new QGroupBox("Disqualified and Non Equestrian");
22
    verticalLayout->addWidget(groupBox);
23
 
24
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
25
 
26
    tableWidget = new QTableWidget(groupBox);
27
    tableWidget->setObjectName(QString::fromUtf8("tableWidget"));
28
    //tableWidget->setGeometry(QRect(10, 20, 501, 421));
29
    tableWidget->setAlternatingRowColors(true);
30
    tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
31
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
32
    tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
33
    verticalLayout2->addWidget(tableWidget);
34
 
276 david 35
    QHBoxLayout *horizontalLayout;
36
    horizontalLayout = new QHBoxLayout();
37
    horizontalLayout->setContentsMargins(0, 0, 0, 5);
38
 
39
    QGroupBox *groupBox2 = new QGroupBox("Bulk Set");
40
    verticalLayout2->addLayout(horizontalLayout);
41
    horizontalLayout->addWidget(groupBox2);
42
 
43
    QHBoxLayout *horizontalLayout1;
44
    QSpacerItem *horizontalSpacer1;
45
 
46
    horizontalLayout1 = new QHBoxLayout();
47
    horizontalLayout1->setContentsMargins(5, 5, 5, 5);
48
    groupBox2->setLayout(horizontalLayout1);
49
 
50
    cb_disq = new QCheckBox("Disq");
51
    cb_disq->setTristate(true);
52
    horizontalLayout1->addWidget(cb_disq);
53
 
54
    cb_ne = new QCheckBox("Non Equest");
55
    cb_ne->setTristate(true);
56
    horizontalLayout1->addWidget(cb_ne);
57
 
58
    cb_enable = new QCheckBox("Enable");
59
    cb_enable->setTristate(true);
60
    horizontalLayout1->addWidget(cb_enable);
61
 
62
    cb_vetcheck = new QCheckBox("Vet Check");
63
    cb_vetcheck->setTristate(true);
64
    horizontalLayout1->addWidget(cb_vetcheck);
65
 
66
    horizontalLayout1->addWidget(new QLabel("Team"));
67
    teamNumber = new QSpinBox();
68
    horizontalLayout1->addWidget(teamNumber);
69
 
70
    setButton = new QPushButton("Set");
71
    horizontalLayout1->addWidget(setButton);
72
 
73
    horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
74
    horizontalLayout1->addItem(horizontalSpacer1);
75
 
194 - 76
    buttonBox = new QDialogButtonBox();
195 david 77
    pb_restore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
78
    pb_save = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
276 david 79
    horizontalLayout->addWidget(buttonBox);
194 - 80
 
195 david 81
    connect(pb_save, SIGNAL(clicked()), this, SLOT(save()) );
82
    connect(pb_restore, SIGNAL(clicked()), this, SLOT(cancel()) );
276 david 83
    connect(setButton, SIGNAL(clicked()), this, SLOT(bulk_set()) );
194 - 84
    connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
195 david 85
    updateChanged (false);
138 david 86
}
87
 
88
qmDisqualified::~qmDisqualified()
89
{
194 - 90
 
138 david 91
}
92
 
93
void qmDisqualified::save(void)
94
{
140 - 95
    team_type team_buf;
194 - 96
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
140 - 97
    {
98
        QTableWidgetItem *item;
194 - 99
        item = tableWidget->item(ii, 0);
140 - 100
        if ( item )
101
        {
102
            if ( item->data(Qt::UserRole + 1).toBool() )
103
            {
104
                int team = item->data(Qt::EditRole).toInt();
105
                if ( team )
106
                {
107
                    qDebug("Detected change:%d", team);
108
                    g_record( team, &team_buf );
109
 
194 - 110
                    item = tableWidget->item(ii,2);
140 - 111
                    team_buf.flags.disqualified =  ( item->checkState () == Qt::Checked);
112
 
194 - 113
                    item = tableWidget->item(ii,3);
140 - 114
                    team_buf.flags.non_equestrian =  ( item->checkState () == Qt::Checked);
115
 
194 - 116
                    item = tableWidget->item(ii,4);
140 - 117
                    team_buf.flags.valid =  ( item->checkState () == Qt::Checked);
118
 
229 - 119
                    item = tableWidget->item(ii,5);
120
                    team_buf.flags.vet_check =  ( item->checkState () == Qt::Checked);
121
 
140 - 122
                    put_team_record( team, &team_buf );
123
                }
124
            }
125
        }
126
    }
127
    populate();
128
 
138 david 129
}
130
 
131
void qmDisqualified::cancel(void)
132
{
133
    populate();
134
}
135
 
136
void qmDisqualified::populate(void)
137
{
138
    team_type team_buf;
139
    inPopulate = TRUE;
140
 
141
    /*
142
    ** Delete existing entries in the table
143
    */
194 - 144
    tableWidget->clearContents();
228 - 145
    tableWidget->setRowCount(config.max_team+1);
229 - 146
    tableWidget->setColumnCount(7);
194 - 147
    tableWidget->setSortingEnabled(FALSE);
138 david 148
 
149
    /*
150
    ** Scan all the team data
151
    */
152
    for ( int team = config.min_team; team <= config.max_team; team++)
153
    {
194 - 154
        tableWidget->hideRow ( team );
138 david 155
        if( valid_field( team ) )
156
        {
157
            g_record( team, &team_buf );
140 - 158
            if( team_buf.flags.valid || true )
138 david 159
            {
182 - 160
                qmDisqualifiedItem *item;
138 david 161
 
194 - 162
                tableWidget->showRow( team );
138 david 163
 
182 - 164
                item = new qmDisqualifiedItem(team);
140 - 165
                item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
194 - 166
                tableWidget->setItem(team, 0, item );
138 david 167
 
182 - 168
                item = new qmDisqualifiedItem(team_buf.name);
140 - 169
                item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
194 - 170
                tableWidget->setItem(team, 1, item );
138 david 171
 
194 - 172
                tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );
173
                tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );
174
                tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );
229 - 175
                tableWidget->setItem(team, 5, new qmDisqualifiedItem("VetCheck", team_buf.flags.vet_check,team) );
193 - 176
 
177
                item = new qmDisqualifiedItem("Bad Times", team_buf.flags.bad_times);
178
                item->setFlags(Qt::ItemIsSelectable/* | Qt::ItemIsEnabled*/);
229 - 179
                tableWidget->setItem(team, 6, item  );
138 david 180
            }
181
        }
182
    }
194 - 183
    tableWidget->sortByColumn(0,Qt::AscendingOrder);
184
    tableWidget->setSortingEnabled(TRUE);
185
    tableWidget->resizeColumnsToContents();
182 - 186
 
276 david 187
    /*
188
     ** Init the bulk_set checkboxes to tristate
189
     */
190
    cb_disq->setCheckState(Qt::PartiallyChecked);
191
    cb_enable->setCheckState(Qt::PartiallyChecked);
192
    cb_ne->setCheckState(Qt::PartiallyChecked);
193
    cb_vetcheck->setCheckState(Qt::PartiallyChecked);
194
 
195
    teamNumber->setMaximum(config.max_team);
196
    teamNumber->setMinimum(config.min_team);
197
 
138 david 198
    inPopulate = FALSE;
195 david 199
    updateChanged(false);
138 david 200
}
201
 
202
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
203
{
204
    if ( !inPopulate )
205
    {
140 - 206
        if ( item->column() )
207
        {
208
            qDebug ("DataChanged");
209
            item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
210
 
211
            // Mark first item in row to help detect changes
212
            int row = item->row();
213
            item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
195 david 214
            item->tableWidget()->item(row,0)->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
140 - 215
        }
195 david 216
 
217
        updateChanged(true);
138 david 218
    }
219
}
182 - 220
 
195 david 221
void qmDisqualified::updateChanged(bool newDirty)
222
{
223
    if (newDirty != dirty)
224
    {
225
        dirty = newDirty;
226
        if (dirty)
227
        {
228
            pb_save->setEnabled(true);
229
            pb_save->setStyleSheet("background-color: rgb(255, 0, 0);");
230
        }
231
        else
232
        {
233
            pb_save->setEnabled(false);
234
            pb_save->setStyleSheet("");
235
        }
236
    }
237
}
238
 
239
void qmDisqualified::showEvent ( QShowEvent * event )
240
{
241
    qDebug("qmDisqualified::showEvent");
242
    if ( ! event->spontaneous() && !dirty )
243
    {
244
        populate();
245
    }
246
}
247
 
276 david 248
/*----------------------------------------------------------------------------
249
** FUNCTION           : bulk_set
250
**
251
** DESCRIPTION        : Set multiple attributes on the current team
252
**
253
**
254
** INPUTS             : Nothing
255
**
256
** RETURNS            : Nothing
257
**
258
----------------------------------------------------------------------------*/
259
 
260
void qmDisqualified::bulk_set(void)
261
{
262
    bool team_found = FALSE;
263
    bool item_set = FALSE;
264
 
265
    //qDebug("qmDisqualified::bulk_set:%d", teamNumber->value());
266
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
267
    {
268
        QTableWidgetItem *item;
269
        item = tableWidget->item(ii, 0);
270
        if ( item )
271
        {
272
            int team = item->data(Qt::EditRole).toInt();
273
            if ( team && team == teamNumber->value() )
274
            {
275
                tableWidget->scrollToItem(item,QAbstractItemView::PositionAtCenter);
276
                //qDebug("Found Entry:%d", team);
277
 
278
                enum Qt::CheckState state;
279
                state = cb_disq->checkState();
280
                if (state != Qt::PartiallyChecked)
281
                {
282
                    item = tableWidget->item(ii,2);
283
                    item->setCheckState(state);
284
                    item_set = TRUE;
285
                }
286
 
287
                state = cb_ne->checkState();
288
                if (state != Qt::PartiallyChecked)
289
                {
290
                    item = tableWidget->item(ii,3);
291
                    item->setCheckState(state);
292
                    item_set = TRUE;
293
                }
294
 
295
                state = cb_enable->checkState();
296
                if (state != Qt::PartiallyChecked)
297
                {
298
                    item = tableWidget->item(ii,4);
299
                    item->setCheckState(state);
300
                    item_set = TRUE;
301
                }
302
 
303
                state = cb_vetcheck->checkState();
304
                if (state != Qt::PartiallyChecked)
305
                {
306
                    item = tableWidget->item(ii,5);
307
                    item->setCheckState(state);
308
                    item_set = TRUE;
309
                }
310
                team_found = TRUE;
311
                break;
312
            }
313
        }
314
    }
315
 
316
    /*
317
    **  Report to user
318
    */
319
    if ( team_found)
320
    {
321
        if (item_set )
322
            MainWindow::showMessage("Values set");
323
        else
324
            MainWindow::showMessage("Nothing selected to set");
325
    }
326
    else
327
    {
328
        MainWindow::showMessage("Team not found");
329
    }
330
}
331
 
332
 
182 - 333
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
334
{
335
    number = 0;
336
}
337
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
338
{
339
    number = value;
340
    setData(0,value);
341
}
342
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
343
{
344
    setCheckState(checked ? Qt::Checked : Qt::Unchecked);
345
    number = num;
346
}
347
 
348
// Special sorting, based on type
349
//      type == 0 : Text
350
//      type == 1 : Number
351
//      type == 2 : Checked
352
//
353
bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const
354
{
355
    const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);
356
    if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 )
357
    {
358
        if (other_widget->checkState() == checkState() )
359
        {
360
//            qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);
361
            if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder )
362
            {
363
                return other_widget->number < number;
364
            }
365
            else
366
            {
367
                return number < other_widget->number;
368
            }
369
        }
370
        return (other_widget->checkState() < checkState() );
371
    }
372
 
373
    return ( QTableWidgetItem::operator< (other) );
374
}
276 david 375
 
376