Subversion Repositories svn1-original

Rev

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

#include <QVBoxLayout>
#include <QGroupBox>
#include <QDialogButtonBox>
#include <QTableWidget>
#include <QHeaderView>
#include "qmfulldata.h"
#include    "consts.h"
#include    "structs.h"
#include    "proto.h"
#include "mainwindow.h"
#include "qmTableWidgetItem.h"
#include "qmDialogTeamEditor.h"


/*----------------------------------------------------------------------------
** FUNCTION           : qmFullData
**
** DESCRIPTION        : Display all the team data in colums that can be sorted 
**
**
** INPUTS             :
**
** RETURNS            :
**
----------------------------------------------------------------------------*/

qmFullData::qmFullData(QWidget *parent) :
    QWidget(parent)
{

    /*
    ** Init vars 
    */
    sorted = false;

    /*
    ** Create the main display region 
    **      A groupbox with a table in it
    **      A 'refresh' button
    */

    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
    verticalLayout->setContentsMargins(0, 0, 0, 0);

    QGroupBox *groupBox = new QGroupBox("Class");
    verticalLayout->addWidget(groupBox);
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
    tableWidget = new QTableWidget(groupBox);
    tableWidget->setAlternatingRowColors(true);
    //tableWidget->setRowCount(config.num_teams + 1);
    //tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    tableWidget->setColumnCount(config.num_legs + 3 + 5);
    tableWidget->horizontalHeader()->setVisible(true);
    tableWidget->horizontalHeader()->setDefaultSectionSize(70);
    tableWidget->horizontalHeader()->setHighlightSections(true);

    tableWidget->verticalHeader()->setVisible(true);
    tableWidget->verticalHeader()->setDefaultSectionSize(20);

    verticalLayout2->addWidget(tableWidget);

    QHBoxLayout *horizontalLayout;
    horizontalLayout = new QHBoxLayout();
    horizontalLayout->setContentsMargins(0, 0, 5, 5);
    verticalLayout->addLayout(horizontalLayout);

    QDialogButtonBox *buttonBox = new QDialogButtonBox();
    refreshButton = buttonBox->addButton("Refresh Data",QDialogButtonBox::ActionRole );
    horizontalLayout->addWidget(buttonBox);

    //  Wire in the button
    connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(loadData()) );
    connect(tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(selectTeam(int,int)));

    // Insert Labels
    QStringList labels;
    labels << "Team" << "Full Name" << "Cat";
    for (int ii = 0; ii < config.num_legs; ii++)
    {
        labels << config.leg_name[ii];
    }
    labels << "Disq" << "NonEq" << "Enabled" << "Vet Check" << "Bad Times";

    tableWidget->setHorizontalHeaderLabels(labels);
    tableWidget->resizeColumnsToContents();
}

/*----------------------------------------------------------------------------
** FUNCTION           : showEvent
**
** DESCRIPTION        : Slot that is wired into the main windows widget
**                      It will be called when the main window widget changes
**                      If this display is the current display, then load new data
**
** INPUTS             : index of the tab that now has focus
**
----------------------------------------------------------------------------*/

void qmFullData::showEvent ( QShowEvent * event )
{
    //qDebug("qmFullData::showEvent");
    if ( ! event->spontaneous() )
    {
        loadData();
    }
}

/*----------------------------------------------------------------------------
** FUNCTION           : loadData
**
** DESCRIPTION        : Load Data into the Window
**
**
** INPUTS             :
**
** RETURNS            :
**
----------------------------------------------------------------------------*/

void qmFullData::loadData(void)
{
    team_type team_buf;

    /*
    ** Delete existing entries in the table
    */
    tableWidget->clearContents();
    tableWidget->setRowCount(config.max_team+1);
    tableWidget->setSortingEnabled(FALSE);

    /*
    ** Scan all the team data
    */
    for ( int team = config.min_team; team <= config.max_team; team++)
    {
        int leg;
        tableWidget->hideRow ( team );
        if( valid_field( team ) )
        {
            g_record( team, &team_buf );
            if( team_buf.flags.valid )
            {
                tableWidget->showRow( team );

                tableWidget->setItem(team, 0, new qmTwiNumber(team) );
                tableWidget->setItem(team, 1, new qmTwiString(team_buf.name));
                tableWidget->setItem(team, 2, new qmTwiString(config.team_class[team_buf.teamclass-1].abr));

                for (leg=0; leg < config.num_legs; leg++)
                {
                    tableWidget->setItem(team, 3 + leg, new qmTwiTime(team_buf.leg[leg+1].elapsed));
                }

                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Disq", team_buf.flags.disqualified) );
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Non Equest",team_buf.flags.non_equestrian) );
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Enable", team_buf.flags.valid) );
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("VetCheck", team_buf.flags.vet_check) );
                tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Bad Times", team_buf.flags.bad_times) );
            }
        }
    }
    if (!sorted)
    {
        tableWidget->sortByColumn(0, Qt::AscendingOrder);
        sorted = true; 
    }
    tableWidget->setSortingEnabled(TRUE);
    tableWidget->resizeColumnsToContents();
}

/*----------------------------------------------------------------------------
** FUNCTION           : selectTeam
**
** DESCRIPTION        : Given a table row/col, locate the team and
**                      if its valid, then open up a modal dialog to
**                      edit the team data.
** 
**                      On return, refresh all data in the page.
**
** INPUTS             :
**
** RETURNS            :
**
----------------------------------------------------------------------------*/

void qmFullData::selectTeam( int row, int col)
{
    //qDebug("qmFullData::selectTeam:%d,%d",row,col);
    QTableWidgetItem *item = tableWidget->item(row,0);
    if (item)
    {
        //qDebug("qmFullData::selectTeam:%d,%d, %p",row,col, item);
        const qmTwiNumber * itemNumber = dynamic_cast<const qmTwiNumber*>(item);
        if ( itemNumber)
        {
            //qDebug("qmFullData::selectTeam: Team:%d",itemNumber->number);
            qmDialogTeamEditor dialog(itemNumber->number, this);
            dialog.exec();
            loadData();
        }

    }
}