Subversion Repositories svn1

Rev

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

Rev 225 Rev 380
Line 1... Line 1...
1
#include "qmdisqualified.h"
1
#include "qmdisqualified.h"
2
#include    "consts.h"
2
#include "consts.h"
3
#include    "structs.h"
3
#include "structs.h"
4
#include    "proto.h"
4
#include "proto.h"
5
#include <QHeaderView>
5
#include <QHeaderView>
-
 
6
#include <QLabel>
6
#include <QPushButton>
7
#include <QGroupBox>
-
 
8
#include "mainwindow.h"
7
 
9
 
8
qmDisqualified::qmDisqualified(QWidget *parent) :
10
qmDisqualified::qmDisqualified(QWidget *parent) :
9
    QWidget(parent)
11
    QWidget(parent)
10
 
12
 
11
{
13
{
Line 28... Line 30...
28
    tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
30
    tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
29
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
31
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
30
    tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
32
    tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
31
    verticalLayout2->addWidget(tableWidget);
33
    verticalLayout2->addWidget(tableWidget);
32
 
34
 
-
 
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
    groupBox2->setToolTip("Set or clear one or more attributes for the specified team."
-
 
50
                           "\nThe attributes have three states: Set,Clear and Do Nothing."
-
 
51
                           "\nSelect the required attributes to change. Enter the team number"
-
 
52
                           "\nand use 'Set' or <Return> to Set/Clear the selected attributes.");
-
 
53
 
-
 
54
    cb_disq = new QCheckBox("Disq");
-
 
55
    cb_disq->setTristate(true);
-
 
56
    horizontalLayout1->addWidget(cb_disq);
-
 
57
 
-
 
58
    cb_ne = new QCheckBox("Non Equest");
-
 
59
    cb_ne->setTristate(true);
-
 
60
    horizontalLayout1->addWidget(cb_ne);
-
 
61
 
-
 
62
    cb_enable = new QCheckBox("Enable");
-
 
63
    cb_enable->setTristate(true);
-
 
64
    horizontalLayout1->addWidget(cb_enable);
-
 
65
 
-
 
66
    cb_vetcheck = new QCheckBox("Vet Check");
-
 
67
    cb_vetcheck->setTristate(true);
-
 
68
    horizontalLayout1->addWidget(cb_vetcheck);
-
 
69
        
-
 
70
    horizontalLayout1->addWidget(new QLabel("Team"));
-
 
71
    teamNumber = new QmTeamSelector();
-
 
72
    horizontalLayout1->addWidget(teamNumber);
-
 
73
 
-
 
74
    setButton = new QPushButton("Set");
-
 
75
    horizontalLayout1->addWidget(setButton);
-
 
76
 
-
 
77
    horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
 
78
    horizontalLayout->addItem(horizontalSpacer1);
-
 
79
 
33
    buttonBox = new QDialogButtonBox();
80
    buttonBox = new QDialogButtonBox();
34
    pb_restore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
81
    pb_restore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
35
    pb_save = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
82
    pb_save = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
36
    verticalLayout->addWidget(buttonBox);
83
    horizontalLayout->addWidget(buttonBox);
37
 
84
 
38
    connect(pb_save, SIGNAL(clicked()), this, SLOT(save()) );
85
    connect(pb_save, SIGNAL(clicked()), this, SLOT(save()) );
39
    connect(pb_restore, SIGNAL(clicked()), this, SLOT(cancel()) );
86
    connect(pb_restore, SIGNAL(clicked()), this, SLOT(cancel()) );
-
 
87
    connect(setButton, SIGNAL(clicked()), this, SLOT(bulk_set()) );
-
 
88
    connect(teamNumber,SIGNAL(teamSelected()), this, SLOT(bulk_set()) );
-
 
89
    connect(teamNumber, SIGNAL(valueChanged(int)), this, SLOT(center_display(int)));
40
    connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
90
    connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
41
    updateChanged (false);
91
    updateChanged (false);
42
}
92
}
43
 
93
 
44
qmDisqualified::~qmDisqualified()
94
qmDisqualified::~qmDisqualified()
Line 58... Line 108...
58
            if ( item->data(Qt::UserRole + 1).toBool() )
108
            if ( item->data(Qt::UserRole + 1).toBool() )
59
            {
109
            {
60
                int team = item->data(Qt::EditRole).toInt();
110
                int team = item->data(Qt::EditRole).toInt();
61
                if ( team )
111
                if ( team )
62
                {
112
                {
63
                    qDebug("Detected change:%d", team);
113
                    //qDebug("Detected change:%d", team);
64
                    g_record( team, &team_buf );
114
                    g_record( team, &team_buf );
65
 
115
 
66
                    item = tableWidget->item(ii,2);
116
                    item = tableWidget->item(ii,2);
67
                    team_buf.flags.disqualified =  ( item->checkState () == Qt::Checked);
117
                    team_buf.flags.disqualified =  ( item->checkState () == Qt::Checked);
68
 
118
 
Line 138... Line 188...
138
    }
188
    }
139
    tableWidget->sortByColumn(0,Qt::AscendingOrder);
189
    tableWidget->sortByColumn(0,Qt::AscendingOrder);
140
    tableWidget->setSortingEnabled(TRUE);
190
    tableWidget->setSortingEnabled(TRUE);
141
    tableWidget->resizeColumnsToContents();
191
    tableWidget->resizeColumnsToContents();
142
 
192
 
-
 
193
    /*
-
 
194
     ** Init the bulk_set checkboxes to tristate
-
 
195
     */
-
 
196
    cb_disq->setCheckState(Qt::PartiallyChecked);
-
 
197
    cb_enable->setCheckState(Qt::PartiallyChecked);
-
 
198
    cb_ne->setCheckState(Qt::PartiallyChecked);
-
 
199
    cb_vetcheck->setCheckState(Qt::PartiallyChecked);
-
 
200
 
-
 
201
    teamNumber->setMaximum(config.max_team);
-
 
202
    teamNumber->setMinimum(config.min_team);
-
 
203
 
143
    inPopulate = FALSE;
204
    inPopulate = FALSE;
144
    updateChanged(false);
205
    updateChanged(false);
145
}
206
}
146
 
207
 
147
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
208
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
148
{
209
{
149
    if ( !inPopulate )
210
    if ( !inPopulate )
150
    {
211
    {
151
        if ( item->column() )
212
        if ( item->column() )
152
        {
213
        {
153
            qDebug ("DataChanged");
214
            //qDebug ("DataChanged");
154
            item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
215
            item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
155
 
216
 
156
            // Mark first item in row to help detect changes
217
            // Mark first item in row to help detect changes
157
            int row = item->row();
218
            int row = item->row();
158
            item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
219
            item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
Line 181... Line 242...
181
    }
242
    }
182
}
243
}
183
 
244
 
184
void qmDisqualified::showEvent ( QShowEvent * event )
245
void qmDisqualified::showEvent ( QShowEvent * event )
185
{
246
{
186
    qDebug("qmDisqualified::showEvent");
247
    //qDebug("qmDisqualified::showEvent");
187
    if ( ! event->spontaneous() && !dirty )
248
    if ( ! event->spontaneous() && !dirty )
188
    {
249
    {
189
        populate();
250
        populate();
190
    }
251
    }
191
}
252
}
192
 
253
 
-
 
254
/*----------------------------------------------------------------------------
-
 
255
** FUNCTION           : bulk_set
-
 
256
**
-
 
257
** DESCRIPTION        : Set multiple attributes on the current team
-
 
258
**
-
 
259
**
-
 
260
** INPUTS             : Nothing
-
 
261
**
-
 
262
** RETURNS            : Nothing
-
 
263
**
-
 
264
----------------------------------------------------------------------------*/
-
 
265
 
-
 
266
void qmDisqualified::bulk_set(void)
-
 
267
{
-
 
268
    bool team_found = FALSE;
-
 
269
    bool item_set = FALSE;
-
 
270
 
-
 
271
    //qDebug("qmDisqualified::bulk_set:%d", teamNumber->value());
-
 
272
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
-
 
273
    {
-
 
274
        QTableWidgetItem *item;
-
 
275
        item = tableWidget->item(ii, 0);
-
 
276
        if ( item )
-
 
277
        {
-
 
278
            int team = item->data(Qt::EditRole).toInt();
-
 
279
            if ( team && team == teamNumber->value() )
-
 
280
            {
-
 
281
                tableWidget->scrollToItem(item,QAbstractItemView::PositionAtCenter);
-
 
282
                //qDebug("Found Entry:%d", team);
-
 
283
 
-
 
284
                enum Qt::CheckState state;
-
 
285
                state = cb_disq->checkState();
-
 
286
                if (state != Qt::PartiallyChecked)
-
 
287
                {
-
 
288
                    item = tableWidget->item(ii,2);
-
 
289
                    item->setCheckState(state);
-
 
290
                    item_set = TRUE;
-
 
291
                }
-
 
292
 
-
 
293
                state = cb_ne->checkState();
-
 
294
                if (state != Qt::PartiallyChecked)
-
 
295
                {
-
 
296
                    item = tableWidget->item(ii,3);
-
 
297
                    item->setCheckState(state);
-
 
298
                    item_set = TRUE;
-
 
299
                }
-
 
300
 
-
 
301
                state = cb_enable->checkState();
-
 
302
                if (state != Qt::PartiallyChecked)
-
 
303
                {
-
 
304
                    item = tableWidget->item(ii,4);
-
 
305
                    item->setCheckState(state);
-
 
306
                    item_set = TRUE;
-
 
307
                }
-
 
308
 
-
 
309
                state = cb_vetcheck->checkState();
-
 
310
                if (state != Qt::PartiallyChecked)
-
 
311
                {
-
 
312
                    item = tableWidget->item(ii,5);
-
 
313
                    item->setCheckState(state);
-
 
314
                    item_set = TRUE;
-
 
315
                }
-
 
316
                team_found = TRUE;
-
 
317
                break;
-
 
318
            }
-
 
319
        }
-
 
320
    }
-
 
321
 
-
 
322
    /*
-
 
323
    **  Report to user
-
 
324
    */
-
 
325
    if ( team_found)
-
 
326
    {
-
 
327
        if (item_set )
-
 
328
            MainWindow::showMessage("Values set");
-
 
329
        else
-
 
330
            MainWindow::showMessage("Nothing selected to set");
-
 
331
    }
-
 
332
    else
-
 
333
    {
-
 
334
        MainWindow::showMessage("Team not found");
-
 
335
    }
-
 
336
}
-
 
337
 
-
 
338
/*----------------------------------------------------------------------------
-
 
339
** FUNCTION           : center_display
-
 
340
**
-
 
341
** DESCRIPTION        : Place the specified team in the center of the display
-
 
342
**                      If not found then place close item in display
-
 
343
**
-
 
344
**
-
 
345
** INPUTS             : teamNumber
-
 
346
**
-
 
347
** RETURNS            : Nothing
-
 
348
**
-
 
349
----------------------------------------------------------------------------*/
-
 
350
 
-
 
351
void qmDisqualified::center_display(int teamNumber)
-
 
352
{
-
 
353
    QTableWidgetItem *item = NULL;
-
 
354
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
-
 
355
    {
-
 
356
        item = tableWidget->item(ii, 0);
-
 
357
        if ( item )
-
 
358
        {
-
 
359
            int team = item->data(Qt::EditRole).toInt();
-
 
360
            if ( team && team >= teamNumber )
-
 
361
            {
-
 
362
                break;
-
 
363
            }
-
 
364
        }
-
 
365
    }
-
 
366
    if ( item )
-
 
367
    {
-
 
368
        tableWidget->scrollToItem(item,QAbstractItemView::PositionAtCenter);
-
 
369
    }
-
 
370
}
-
 
371
 
193
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
372
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
194
{
373
{
195
    number = 0;
374
    number = 0;
196
}
375
}
197
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
376
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
Line 230... Line 409...
230
        return (other_widget->checkState() < checkState() );
409
        return (other_widget->checkState() < checkState() );
231
    }
410
    }
232
 
411
 
233
    return ( QTableWidgetItem::operator< (other) );
412
    return ( QTableWidgetItem::operator< (other) );
234
}
413
}
-
 
414
 
-
 
415