Subversion Repositories svn1

Rev

Rev 163 | Rev 165 | 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
25
    QTableWidget *tb = new QTableWidget(config.num_class + 1,4);
164 david 26
    //tb->horizontalHeader()->setStretchLastSection(true);
163 david 27
    tb->horizontalHeader()->setAlternatingRowColors(true);
28
    tb->horizontalHeader()->setSortIndicatorShown(true);
29
    QStringList labels;
30
    labels << "Category" << "Total" << "Disq" << "NonEq";
31
    tb->setHorizontalHeaderLabels(labels);
32
    tb->verticalHeader()->setDefaultSectionSize(17);
33
    tb->setSortingEnabled(false);
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));
163 david 49
        }
50
 
164 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));
163 david 55
 
164 david 56
        tb->sortItems ( 0, Qt::AscendingOrder );
57
        tb->setSortingEnabled(true);
163 david 58
        tb->resizeColumnsToContents();
59
        tb->resizeRowsToContents();
60
    }
61
}
164 david 62
 
63
QmDialogStatusTableItem::QmDialogStatusTableItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
64
{
65
}
66
QmDialogStatusTableItem::QmDialogStatusTableItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
67
{
68
    setData(0,value);
69
}
70
 
71
// Returns true if the item is less than the other item; otherwise returns false.
72
// Ensure that marked rowas are sorted as 'always' highest
73
bool QmDialogStatusTableItem::operator< ( const QTableWidgetItem & other ) const
74
{
75
    if (type() != QTableWidgetItem::UserType )
76
    {
77
        return (false);
78
    }
79
 
80
    const QmDialogStatusTableItem * other_widget = dynamic_cast<const QmDialogStatusTableItem*>(&other);
81
    if (other_widget && other_widget->type() != QTableWidgetItem::UserType )
82
    {
83
        return true;
84
    }
85
 
86
    return ( QTableWidgetItem::operator< (other) );
87
}