Subversion Repositories svn1

Rev

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

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