Subversion Repositories svn1

Rev

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

Rev Author Line No. Line
163 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
225 - 25
    QTableWidget *tb = new QTableWidget(config.num_class + 1,5);
164 david 26
    //tb->horizontalHeader()->setStretchLastSection(true);
163 david 27
    tb->horizontalHeader()->setSortIndicatorShown(true);
28
    QStringList labels;
225 - 29
    labels << "Category" << "Total" << "Disq" << "NonEq" << "VetCheck";
163 david 30
    tb->setHorizontalHeaderLabels(labels);
31
    tb->verticalHeader()->setDefaultSectionSize(17);
32
    tb->setSortingEnabled(false);
165 david 33
    tb->setAlternatingRowColors(true);
163 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
        {
164 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));
47
            tb->setItem(ii,2, new QmDialogStatusTableItem(data.teamclass[ii+1].disqualified,0));
48
            tb->setItem(ii,3, new QmDialogStatusTableItem(data.teamclass[ii+1].non_equestrian,0));
225 - 49
            tb->setItem(ii,4, new QmDialogStatusTableItem(data.teamclass[ii+1].vet_check,0));
163 david 50
        }
51
 
164 david 52
        tb->setItem(ii,0, new QmDialogStatusTableItem("Totals", 1));
53
        tb->setItem(ii,1, new QmDialogStatusTableItem(data.total.total, 1));
54
        tb->setItem(ii,2, new QmDialogStatusTableItem(data.total.disqualified, 1));
55
        tb->setItem(ii,3, new QmDialogStatusTableItem(data.total.non_equestrian, 1));
225 - 56
        tb->setItem(ii,4, new QmDialogStatusTableItem(data.total.vet_check, 1));
163 david 57
 
164 david 58
        tb->sortItems ( 0, Qt::AscendingOrder );
59
        tb->setSortingEnabled(true);
163 david 60
        tb->resizeColumnsToContents();
61
        tb->resizeRowsToContents();
165 david 62
 
167 david 63
        // Kludge. It not corrcet, but it does size the screen
166 david 64
        resize(tb->viewport()->size());
163 david 65
    }
66
}
164 david 67
 
68
QmDialogStatusTableItem::QmDialogStatusTableItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
69
{
70
}
71
QmDialogStatusTableItem::QmDialogStatusTableItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
72
{
73
    setData(0,value);
74
}
75
 
76
// Returns true if the item is less than the other item; otherwise returns false.
77
// Ensure that marked rowas are sorted as 'always' highest
78
bool QmDialogStatusTableItem::operator< ( const QTableWidgetItem & other ) const
79
{
80
    if (type() != QTableWidgetItem::UserType )
81
    {
82
        return (false);
83
    }
84
 
85
    const QmDialogStatusTableItem * other_widget = dynamic_cast<const QmDialogStatusTableItem*>(&other);
86
    if (other_widget && other_widget->type() != QTableWidgetItem::UserType )
87
    {
88
        return true;
89
    }
90
 
91
    return ( QTableWidgetItem::operator< (other) );
92
}