Subversion Repositories svn1

Rev

Rev 225 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "qmdialogstatus.h"
#include <QGroupBox>
#include <QTableWidget>
#include <QVBoxLayout>
#include <QStringList>
#include <QHeaderView>

#include    "consts.h"
#include    "structs.h"
#include    "proto.h"

QmDialogStatus::QmDialogStatus(QWidget *parent) : QDialog(parent)
{
    QVBoxLayout *layout = new QVBoxLayout;
    setLayout(layout);
    setSizeGripEnabled(true);

    QGroupBox *gb = new QGroupBox("Summary Display", this);
    layout->addWidget(gb);

    QVBoxLayout *layout2 = new QVBoxLayout;
    gb->setLayout(layout2);

    // Table Header
    QTableWidget *tb = new QTableWidget(config.num_class + 1,6);
    //tb->horizontalHeader()->setStretchLastSection(true);
    tb->horizontalHeader()->setSortIndicatorShown(true);
    QStringList labels;
    labels << "Category" << "Total" << "Valid" << "Disq" << "NonEq" << "VetCheck";
    tb->setHorizontalHeaderLabels(labels);
    tb->verticalHeader()->setDefaultSectionSize(17);
    tb->setSortingEnabled(false);
    tb->setAlternatingRowColors(true);
    layout2->addWidget(tb);

    if( load_report_data() )
    {
        t_class_summary data;
        calc_class_summary( & data );

        // Insert summary data
        int ii;
        for (ii = 0; ii < config.num_class; ii++)
        {
            tb->setItem(ii,0, new QmDialogStatusTableItem(config.team_class[ii].full_name));
            tb->setItem(ii,1, new QmDialogStatusTableItem(data.teamclass[ii+1].total));
            tb->setItem(ii,2, new QmDialogStatusTableItem(data.teamclass[ii+1].valid));
            tb->setItem(ii,3, new QmDialogStatusTableItem(data.teamclass[ii+1].disqualified,0));
            tb->setItem(ii,4, new QmDialogStatusTableItem(data.teamclass[ii+1].non_equestrian,0));
            tb->setItem(ii,5, new QmDialogStatusTableItem(data.teamclass[ii+1].vet_check,0));
        }

        tb->setItem(ii,0, new QmDialogStatusTableItem("Totals", 1));
        tb->setItem(ii,1, new QmDialogStatusTableItem(data.total.total, 1));
        tb->setItem(ii,2, new QmDialogStatusTableItem(data.total.valid, 1));
        tb->setItem(ii,3, new QmDialogStatusTableItem(data.total.disqualified, 1));
        tb->setItem(ii,4, new QmDialogStatusTableItem(data.total.non_equestrian, 1));
        tb->setItem(ii,5, new QmDialogStatusTableItem(data.total.vet_check, 1));

        tb->sortItems ( 0, Qt::AscendingOrder );
        tb->setSortingEnabled(true);
        tb->resizeColumnsToContents();
        tb->resizeRowsToContents();

        // Kludge. It not corrcet, but it does size the screen
        resize(tb->viewport()->size());
    }
}

QmDialogStatusTableItem::QmDialogStatusTableItem ( const QString & text, int type ) :  QTableWidgetItem(text, type+QTableWidgetItem::UserType)
{
}
QmDialogStatusTableItem::QmDialogStatusTableItem ( int value, int type ) :  QTableWidgetItem(type+QTableWidgetItem::UserType)
{
    setData(0,value);
}

// Returns true if the item is less than the other item; otherwise returns false.
// Ensure that marked rowas are sorted as 'always' highest
bool QmDialogStatusTableItem::operator< ( const QTableWidgetItem & other ) const
{
    if (type() != QTableWidgetItem::UserType )
    {
        return (false);
    }

    const QmDialogStatusTableItem * other_widget = dynamic_cast<const QmDialogStatusTableItem*>(&other);
    if (other_widget && other_widget->type() != QTableWidgetItem::UserType )
    {
        return true;
    }

    return ( QTableWidgetItem::operator< (other) );
}