Subversion Repositories svn1-original

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
167 david 1
#include "qmdialogstatus.h"
2
#include <QGroupBox>
3
#include <QTableWidget>
4
#include <QVBoxLayout>
5
#include <QStringList>
6
#include <QHeaderView>
7
 
8
#include    "consts.h"
9
#include    "structs.h"
10
#include    "proto.h"
11
 
12
QmDialogStatus::QmDialogStatus(QWidget *parent) : QDialog(parent)
13
{
14
    QVBoxLayout *layout = new QVBoxLayout;
15
    setLayout(layout);
16
    setSizeGripEnabled(true);
17
 
18
    QGroupBox *gb = new QGroupBox("Summary Display", this);
19
    layout->addWidget(gb);
20
 
21
    QVBoxLayout *layout2 = new QVBoxLayout;
22
    gb->setLayout(layout2);
23
 
24
    // Table Header
288 david 25
    QTableWidget *tb = new QTableWidget(config.num_class + 1,8);
168 david 26
    //tb->horizontalHeader()->setStretchLastSection(true);
167 david 27
    tb->horizontalHeader()->setSortIndicatorShown(true);
28
    QStringList labels;
288 david 29
    labels << "Category" << "Total" << "Valid" << "Disq" << "NonEq" << "VetCheck" << "Comp Ev" << "Comp NE";
167 david 30
    tb->setHorizontalHeaderLabels(labels);
31
    tb->verticalHeader()->setDefaultSectionSize(17);
32
    tb->setSortingEnabled(false);
169 david 33
    tb->setAlternatingRowColors(true);
167 david 34
    layout2->addWidget(tb);
35
 
36
    if( load_report_data() )
37
    {
38
        t_class_summary data;
39
        calc_class_summary( & data );
40
 
41
        // Insert summary data
42
        int ii;
43
        for (ii = 0; ii < config.num_class; ii++)
44
        {
168 david 45
            tb->setItem(ii,0, new QmDialogStatusTableItem(config.team_class[ii].full_name));
46
            tb->setItem(ii,1, new QmDialogStatusTableItem(data.teamclass[ii+1].total));
232 - 47
            tb->setItem(ii,2, new QmDialogStatusTableItem(data.teamclass[ii+1].valid));
48
            tb->setItem(ii,3, new QmDialogStatusTableItem(data.teamclass[ii+1].disqualified,0));
49
            tb->setItem(ii,4, new QmDialogStatusTableItem(data.teamclass[ii+1].non_equestrian,0));
50
            tb->setItem(ii,5, new QmDialogStatusTableItem(data.teamclass[ii+1].vet_check,0));
288 david 51
            tb->setItem(ii,6, new QmDialogStatusTableItem(data.teamclass[ii+1].valid_ev,0));
52
            tb->setItem(ii,7, new QmDialogStatusTableItem(data.teamclass[ii+1].valid_ne,0));
167 david 53
        }
54
 
168 david 55
        tb->setItem(ii,0, new QmDialogStatusTableItem("Totals", 1));
56
        tb->setItem(ii,1, new QmDialogStatusTableItem(data.total.total, 1));
232 - 57
        tb->setItem(ii,2, new QmDialogStatusTableItem(data.total.valid, 1));
58
        tb->setItem(ii,3, new QmDialogStatusTableItem(data.total.disqualified, 1));
59
        tb->setItem(ii,4, new QmDialogStatusTableItem(data.total.non_equestrian, 1));
60
        tb->setItem(ii,5, new QmDialogStatusTableItem(data.total.vet_check, 1));
288 david 61
        tb->setItem(ii,6, new QmDialogStatusTableItem(data.total.valid_ev, 1));
62
        tb->setItem(ii,7, new QmDialogStatusTableItem(data.total.valid_ne, 1));
167 david 63
 
168 david 64
        tb->sortItems ( 0, Qt::AscendingOrder );
65
        tb->setSortingEnabled(true);
167 david 66
        tb->resizeColumnsToContents();
67
        tb->resizeRowsToContents();
169 david 68
 
171 david 69
        // Kludge. It not corrcet, but it does size the screen
170 david 70
        resize(tb->viewport()->size());
167 david 71
    }
72
}
168 david 73
 
74
QmDialogStatusTableItem::QmDialogStatusTableItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
75
{
76
}
77
QmDialogStatusTableItem::QmDialogStatusTableItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
78
{
79
    setData(0,value);
80
}
81
 
82
// Returns true if the item is less than the other item; otherwise returns false.
83
// Ensure that marked rowas are sorted as 'always' highest
84
bool QmDialogStatusTableItem::operator< ( const QTableWidgetItem & other ) const
85
{
86
    if (type() != QTableWidgetItem::UserType )
87
    {
88
        return (false);
89
    }
90
 
91
    const QmDialogStatusTableItem * other_widget = dynamic_cast<const QmDialogStatusTableItem*>(&other);
92
    if (other_widget && other_widget->type() != QTableWidgetItem::UserType )
93
    {
94
        return true;
95
    }
96
 
97
    return ( QTableWidgetItem::operator< (other) );
98
}