Subversion Repositories svn1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
134 david 1
#include "qmdisqualified.h"
2
#include    "consts.h"
3
#include    "structs.h"
4
#include    "proto.h"
190 - 5
#include <QHeaderView>
134 david 6
 
7
qmDisqualified::qmDisqualified(QWidget *parent) :
190 - 8
    QWidget(parent)
9
 
134 david 10
{
11
    inPopulate = FALSE;
190 - 12
    resize ( 600,400);
134 david 13
 
190 - 14
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
15
    verticalLayout->setContentsMargins(0, 0, 0, 0);
16
 
17
    QGroupBox *groupBox = new QGroupBox("Disqualified and Non Equestrian");
18
    verticalLayout->addWidget(groupBox);
19
 
20
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
21
 
22
    tableWidget = new QTableWidget(groupBox);
23
    tableWidget->setObjectName(QString::fromUtf8("tableWidget"));
24
    //tableWidget->setGeometry(QRect(10, 20, 501, 421));
25
    tableWidget->setAlternatingRowColors(true);
26
    tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
27
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
28
    tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
29
    verticalLayout2->addWidget(tableWidget);
30
 
31
    buttonBox = new QDialogButtonBox();
32
    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
33
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
34
    buttonBox->addButton("Load",QDialogButtonBox::ActionRole );
35
    verticalLayout->addWidget(buttonBox);
36
 
37
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
38
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
39
    //connect(buttonBox, SIGNAL(????), this, SLOT(populate()) );
40
    connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
134 david 41
}
42
 
43
qmDisqualified::~qmDisqualified()
44
{
190 - 45
 
134 david 46
}
47
 
48
void qmDisqualified::save(void)
49
{
136 - 50
    team_type team_buf;
190 - 51
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
136 - 52
    {
53
        QTableWidgetItem *item;
190 - 54
        item = tableWidget->item(ii, 0);
136 - 55
        if ( item )
56
        {
57
            if ( item->data(Qt::UserRole + 1).toBool() )
58
            {
59
                int team = item->data(Qt::EditRole).toInt();
60
                if ( team )
61
                {
62
                    qDebug("Detected change:%d", team);
63
                    g_record( team, &team_buf );
64
 
190 - 65
                    item = tableWidget->item(ii,2);
136 - 66
                    team_buf.flags.disqualified =  ( item->checkState () == Qt::Checked);
67
 
190 - 68
                    item = tableWidget->item(ii,3);
136 - 69
                    team_buf.flags.non_equestrian =  ( item->checkState () == Qt::Checked);
70
//TODO: If nonEquestrian, then also disqualified ??  Original is.
71
 
190 - 72
                    item = tableWidget->item(ii,4);
136 - 73
                    team_buf.flags.valid =  ( item->checkState () == Qt::Checked);
74
 
75
                    put_team_record( team, &team_buf );
76
                }
77
            }
78
        }
79
    }
80
    populate();
81
 
134 david 82
}
83
 
84
void qmDisqualified::cancel(void)
85
{
86
    populate();
87
}
88
 
89
void qmDisqualified::populate(void)
90
{
91
    team_type team_buf;
92
    inPopulate = TRUE;
93
 
94
    /*
95
    ** Delete existing entries in the table
96
    */
190 - 97
    tableWidget->clearContents();
98
    tableWidget->setRowCount(config.max_team);
99
    tableWidget->setColumnCount(6);
100
    tableWidget->setSortingEnabled(FALSE);
134 david 101
 
102
    /*
103
    ** Scan all the team data
104
    */
105
    for ( int team = config.min_team; team <= config.max_team; team++)
106
    {
190 - 107
        tableWidget->hideRow ( team );
134 david 108
        if( valid_field( team ) )
109
        {
110
            g_record( team, &team_buf );
136 - 111
            if( team_buf.flags.valid || true )
134 david 112
            {
178 - 113
                qmDisqualifiedItem *item;
134 david 114
 
190 - 115
                tableWidget->showRow( team );
134 david 116
 
178 - 117
                item = new qmDisqualifiedItem(team);
136 - 118
                item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
190 - 119
                tableWidget->setItem(team, 0, item );
134 david 120
 
178 - 121
                item = new qmDisqualifiedItem(team_buf.name);
136 - 122
                item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
190 - 123
                tableWidget->setItem(team, 1, item );
134 david 124
 
190 - 125
                tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );
126
                tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );
127
                tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );
189 - 128
 
129
                item = new qmDisqualifiedItem("Bad Times", team_buf.flags.bad_times);
130
                item->setFlags(Qt::ItemIsSelectable/* | Qt::ItemIsEnabled*/);
190 - 131
                tableWidget->setItem(team, 5, item  );
134 david 132
            }
133
        }
134
    }
190 - 135
    tableWidget->sortByColumn(0,Qt::AscendingOrder);
136
    tableWidget->setSortingEnabled(TRUE);
137
    tableWidget->resizeColumnsToContents();
178 - 138
 
134 david 139
    inPopulate = FALSE;
140
}
141
 
142
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
143
{
144
    if ( !inPopulate )
145
    {
136 - 146
        if ( item->column() )
147
        {
148
            qDebug ("DataChanged");
149
            item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
150
 
151
            // Mark first item in row to help detect changes
152
            int row = item->row();
153
            item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
154
        }
134 david 155
    }
156
}
178 - 157
 
158
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
159
{
160
    number = 0;
161
}
162
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
163
{
164
    number = value;
165
    setData(0,value);
166
}
167
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
168
{
169
    setCheckState(checked ? Qt::Checked : Qt::Unchecked);
170
    number = num;
171
}
172
 
173
// Special sorting, based on type
174
//      type == 0 : Text
175
//      type == 1 : Number
176
//      type == 2 : Checked
177
//
178
bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const
179
{
180
    const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);
181
    if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 )
182
    {
183
        if (other_widget->checkState() == checkState() )
184
        {
185
//            qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);
186
            if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder )
187
            {
188
                return other_widget->number < number;
189
            }
190
            else
191
            {
192
                return number < other_widget->number;
193
            }
194
        }
195
        return (other_widget->checkState() < checkState() );
196
    }
197
 
198
    return ( QTableWidgetItem::operator< (other) );
199
}