Subversion Repositories svn1-original

Rev

Rev 170 | Rev 229 | Go to most recent revision | Details | Compare with Previous | 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
25
    QTableWidget *tb = new QTableWidget(config.num_class + 1,4);
168 david 26
    //tb->horizontalHeader()->setStretchLastSection(true);
167 david 27
    tb->horizontalHeader()->setSortIndicatorShown(true);
28
    QStringList labels;
29
    labels << "Category" << "Total" << "Disq" << "NonEq";
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));
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));
167 david 49
        }
50
 
168 david 51
        tb->setItem(ii,0, new QmDialogStatusTableItem("Totals", 1));
52
        tb->setItem(ii,1, new QmDialogStatusTableItem(data.total.total, 1));
53
        tb->setItem(ii,2, new QmDialogStatusTableItem(data.total.disqualified, 1));
54
        tb->setItem(ii,3, new QmDialogStatusTableItem(data.total.non_equestrian, 1));
167 david 55
 
168 david 56
        tb->sortItems ( 0, Qt::AscendingOrder );
57
        tb->setSortingEnabled(true);
167 david 58
        tb->resizeColumnsToContents();
59
        tb->resizeRowsToContents();
169 david 60
 
171 david 61
        // Kludge. It not corrcet, but it does size the screen
170 david 62
        resize(tb->viewport()->size());
167 david 63
    }
64
}
168 david 65
 
66
QmDialogStatusTableItem::QmDialogStatusTableItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
67
{
68
}
69
QmDialogStatusTableItem::QmDialogStatusTableItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
70
{
71
    setData(0,value);
72
}
73
 
74
// Returns true if the item is less than the other item; otherwise returns false.
75
// Ensure that marked rowas are sorted as 'always' highest
76
bool QmDialogStatusTableItem::operator< ( const QTableWidgetItem & other ) const
77
{
78
    if (type() != QTableWidgetItem::UserType )
79
    {
80
        return (false);
81
    }
82
 
83
    const QmDialogStatusTableItem * other_widget = dynamic_cast<const QmDialogStatusTableItem*>(&other);
84
    if (other_widget && other_widget->type() != QTableWidgetItem::UserType )
85
    {
86
        return true;
87
    }
88
 
89
    return ( QTableWidgetItem::operator< (other) );
90
}