Subversion Repositories svn1

Rev

Rev 380 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
307 david 1
#include <QVBoxLayout>
2
#include <QGroupBox>
3
#include <QDialogButtonBox>
4
#include <QTableWidget>
5
#include <QHeaderView>
6
#include "qmfulldata.h"
7
#include    "consts.h"
8
#include    "structs.h"
9
#include    "proto.h"
10
#include "mainwindow.h"
310 david 11
#include "qmTableWidgetItem.h"
12
#include "qmDialogTeamEditor.h"
307 david 13
 
14
 
308 david 15
/*----------------------------------------------------------------------------
16
** FUNCTION           : qmFullData
17
**
18
** DESCRIPTION        : Display all the team data in colums that can be sorted 
19
**
20
**
21
** INPUTS             :
22
**
23
** RETURNS            :
24
**
25
----------------------------------------------------------------------------*/
307 david 26
 
27
qmFullData::qmFullData(QWidget *parent) :
28
    QWidget(parent)
29
{
308 david 30
 
31
    /*
314 david 32
    ** Init vars 
33
    */
34
    sorted = false;
35
 
36
    /*
308 david 37
    ** Create the main display region 
38
    **      A groupbox with a table in it
39
    **      A 'refresh' button
40
    */
41
 
307 david 42
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
43
    verticalLayout->setContentsMargins(0, 0, 0, 0);
44
 
45
    QGroupBox *groupBox = new QGroupBox("Class");
46
    verticalLayout->addWidget(groupBox);
47
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
48
    tableWidget = new QTableWidget(groupBox);
49
    tableWidget->setAlternatingRowColors(true);
308 david 50
    //tableWidget->setRowCount(config.num_teams + 1);
307 david 51
    //tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
314 david 52
    tableWidget->setColumnCount(config.num_legs + 3 + 5);
307 david 53
    tableWidget->horizontalHeader()->setVisible(true);
54
    tableWidget->horizontalHeader()->setDefaultSectionSize(70);
55
    tableWidget->horizontalHeader()->setHighlightSections(true);
56
 
57
    tableWidget->verticalHeader()->setVisible(true);
58
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
59
 
60
    verticalLayout2->addWidget(tableWidget);
61
 
62
    QHBoxLayout *horizontalLayout;
63
    horizontalLayout = new QHBoxLayout();
64
    horizontalLayout->setContentsMargins(0, 0, 5, 5);
65
    verticalLayout->addLayout(horizontalLayout);
66
 
67
    QDialogButtonBox *buttonBox = new QDialogButtonBox();
68
    refreshButton = buttonBox->addButton("Refresh Data",QDialogButtonBox::ActionRole );
69
    horizontalLayout->addWidget(buttonBox);
70
 
71
    //  Wire in the button
72
    connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(loadData()) );
73
    connect(tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(selectTeam(int,int)));
74
 
75
    // Insert Labels
76
    QStringList labels;
77
    labels << "Team" << "Full Name" << "Cat";
78
    for (int ii = 0; ii < config.num_legs; ii++)
79
    {
80
        labels << config.leg_name[ii];
81
    }
314 david 82
    labels << "Disq" << "NonEq" << "Enabled" << "Vet Check" << "Bad Times";
307 david 83
 
84
    tableWidget->setHorizontalHeaderLabels(labels);
85
    tableWidget->resizeColumnsToContents();
86
}
87
 
308 david 88
/*----------------------------------------------------------------------------
89
** FUNCTION           : showEvent
90
**
91
** DESCRIPTION        : Slot that is wired into the main windows widget
92
**                      It will be called when the main window widget changes
93
**                      If this display is the current display, then load new data
94
**
95
** INPUTS             : index of the tab that now has focus
96
**
97
----------------------------------------------------------------------------*/
98
 
99
void qmFullData::showEvent ( QShowEvent * event )
100
{
314 david 101
    //qDebug("qmFullData::showEvent");
308 david 102
    if ( ! event->spontaneous() )
103
    {
104
        loadData();
105
    }
106
}
107
 
108
/*----------------------------------------------------------------------------
109
** FUNCTION           : loadData
110
**
111
** DESCRIPTION        : Load Data into the Window
112
**
113
**
114
** INPUTS             :
115
**
116
** RETURNS            :
117
**
118
----------------------------------------------------------------------------*/
119
 
307 david 120
void qmFullData::loadData(void)
121
{
122
    team_type team_buf;
123
 
124
    /*
125
    ** Delete existing entries in the table
126
    */
127
    tableWidget->clearContents();
128
    tableWidget->setRowCount(config.max_team+1);
129
    tableWidget->setSortingEnabled(FALSE);
130
 
131
    /*
132
    ** Scan all the team data
133
    */
134
    for ( int team = config.min_team; team <= config.max_team; team++)
135
    {
136
        int leg;
137
        tableWidget->hideRow ( team );
138
        if( valid_field( team ) )
139
        {
140
            g_record( team, &team_buf );
141
            if( team_buf.flags.valid )
142
            {
143
                tableWidget->showRow( team );
144
 
145
                tableWidget->setItem(team, 0, new qmTwiNumber(team) );
146
                tableWidget->setItem(team, 1, new qmTwiString(team_buf.name));
147
                tableWidget->setItem(team, 2, new qmTwiString(config.team_class[team_buf.teamclass-1].abr));
148
 
149
                for (leg=0; leg < config.num_legs; leg++)
150
                {
151
                    tableWidget->setItem(team, 3 + leg, new qmTwiTime(team_buf.leg[leg+1].elapsed));
152
                }
153
 
154
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Disq", team_buf.flags.disqualified) );
155
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Non Equest",team_buf.flags.non_equestrian) );
156
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Enable", team_buf.flags.valid) );
157
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("VetCheck", team_buf.flags.vet_check) );
158
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Bad Times", team_buf.flags.bad_times) );
159
            }
160
        }
161
    }
314 david 162
    if (!sorted)
163
    {
164
        tableWidget->sortByColumn(0, Qt::AscendingOrder);
165
        sorted = true; 
166
    }
307 david 167
    tableWidget->setSortingEnabled(TRUE);
168
    tableWidget->resizeColumnsToContents();
169
}
170
 
308 david 171
/*----------------------------------------------------------------------------
172
** FUNCTION           : selectTeam
173
**
174
** DESCRIPTION        : Given a table row/col, locate the team and
175
**                      if its valid, then open up a modal dialog to
176
**                      edit the team data.
177
** 
178
**                      On return, refresh all data in the page.
179
**
180
** INPUTS             :
181
**
182
** RETURNS            :
183
**
184
----------------------------------------------------------------------------*/
185
 
307 david 186
void qmFullData::selectTeam( int row, int col)
187
{
188
    //qDebug("qmFullData::selectTeam:%d,%d",row,col);
189
    QTableWidgetItem *item = tableWidget->item(row,0);
190
    if (item)
191
    {
308 david 192
        //qDebug("qmFullData::selectTeam:%d,%d, %p",row,col, item);
307 david 193
        const qmTwiNumber * itemNumber = dynamic_cast<const qmTwiNumber*>(item);
194
        if ( itemNumber)
308 david 195
        {
196
            //qDebug("qmFullData::selectTeam: Team:%d",itemNumber->number);
307 david 197
            qmDialogTeamEditor dialog(itemNumber->number, this);
198
            dialog.exec();
199
            loadData();
308 david 200
        }
307 david 201
 
202
    }
203
}
204