Rev 136 | Rev 190 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "qmdisqualified.h"#include "ui_qmdisqualified.h"#include "consts.h"#include "structs.h"#include "proto.h"qmDisqualified::qmDisqualified(QWidget *parent) :QWidget(parent),ui(new Ui::qmDisqualified){inPopulate = FALSE;ui->setupUi(this);connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );connect(ui->loadButton, SIGNAL(released()), this, SLOT(populate()) );connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));}qmDisqualified::~qmDisqualified(){delete ui;}void qmDisqualified::save(void){team_type team_buf;for ( int ii = 0; ii < ui->tableWidget->rowCount(); ii++){QTableWidgetItem *item;item = ui->tableWidget->item(ii, 0);if ( item ){if ( item->data(Qt::UserRole + 1).toBool() ){int team = item->data(Qt::EditRole).toInt();if ( team ){qDebug("Detected change:%d", team);g_record( team, &team_buf );item = ui->tableWidget->item(ii,2);team_buf.flags.disqualified = ( item->checkState () == Qt::Checked);item = ui->tableWidget->item(ii,3);team_buf.flags.non_equestrian = ( item->checkState () == Qt::Checked);//TODO: If nonEquestrian, then also disqualified ?? Original is.item = ui->tableWidget->item(ii,4);team_buf.flags.valid = ( item->checkState () == Qt::Checked);put_team_record( team, &team_buf );}}}}populate();}void qmDisqualified::cancel(void){populate();}void qmDisqualified::populate(void){team_type team_buf;inPopulate = TRUE;/*** Delete existing entries in the table*/ui->tableWidget->clearContents();ui->tableWidget->setRowCount(config.max_team);ui->tableWidget->setColumnCount(5);ui->tableWidget->setSortingEnabled(FALSE);/*** Scan all the team data*/for ( int team = config.min_team; team <= config.max_team; team++){ui->tableWidget->hideRow ( team );if( valid_field( team ) ){g_record( team, &team_buf );if( team_buf.flags.valid || true ){qmDisqualifiedItem *item;ui->tableWidget->showRow( team );item = new qmDisqualifiedItem(team);item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);ui->tableWidget->setItem(team, 0, item );item = new qmDisqualifiedItem(team_buf.name);item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);ui->tableWidget->setItem(team, 1, item );ui->tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );ui->tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );ui->tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );}}}ui->tableWidget->sortByColumn(0,Qt::AscendingOrder);ui->tableWidget->setSortingEnabled(TRUE);ui->tableWidget->resizeColumnsToContents();inPopulate = FALSE;}void qmDisqualified::tableItemChanged(QTableWidgetItem *item){if ( !inPopulate ){if ( item->column() ){qDebug ("DataChanged");item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));// Mark first item in row to help detect changesint row = item->row();item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );}}}qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType){number = 0;}qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) : QTableWidgetItem(type+QTableWidgetItem::UserType){number = value;setData(0,value);}qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType){setCheckState(checked ? Qt::Checked : Qt::Unchecked);number = num;}// Special sorting, based on type// type == 0 : Text// type == 1 : Number// type == 2 : Checked//bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const{const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 ){if (other_widget->checkState() == checkState() ){// qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder ){return other_widget->number < number;}else{return number < other_widget->number;}}return (other_widget->checkState() < checkState() );}return ( QTableWidgetItem::operator< (other) );}