Subversion Repositories svn1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
302 david 1
#include "qmdialogchangeteamnumber.h"
2
#include "ui_qmdialogchangeteamnumber.h"
303 david 3
#include "mainwindow.h"
4
#include <QPushButton>>
302 david 5
 
6
 
7
QmDialogChangeTeamNumber::QmDialogChangeTeamNumber(const QString &title, QWidget *parent) :
8
    QDialog(parent),
9
    ui(new Ui::QmDialogChangeTeamNumber)
10
{
11
    ui->setupUi(this);
12
    this->setWindowTitle(title);
13
 
14
    ui->sourceTeam->setMinimum(config.min_team);
15
    ui->sourceTeam->setMaximum(config.max_team);
16
    ui->sourceTeam->setValue(0);
303 david 17
    sourceTeam = 0;
302 david 18
 
19
    ui->targetTeam->setMinimum(config.min_team);
20
    ui->targetTeam->setMaximum(config.max_team);
21
    ui->targetTeam->setValue(0);
303 david 22
    targetTeam = 0;
302 david 23
 
303 david 24
    checkValidOpr();
25
 
26
    // Connect up the signals
27
    connect(ui->sourceTeam, SIGNAL(valueChanged(int)), this, SLOT(updateSourceName(int)) );
28
    connect(ui->targetTeam, SIGNAL(valueChanged(int)), this, SLOT(updateTargetName(int)) );
29
 
302 david 30
}
31
 
32
QmDialogChangeTeamNumber::~QmDialogChangeTeamNumber()
33
{
34
    delete ui;
35
}
36
 
303 david 37
bool QmDialogChangeTeamNumber::checkValidOpr(void)
302 david 38
{
303 david 39
    bool valid = true;
302 david 40
 
303 david 41
    //  Ensure that the user has entered something
42
    //
43
    if ( sourceTeam == 0 || targetTeam == 0 )
44
    {
45
        valid = false;
46
    }
302 david 47
 
48
    //  Can't move or copy to myself
49
    //
50
    if ( ui->sourceTeam->value() == ui->targetTeam->value() )
51
    {
303 david 52
        valid = false;
53
    }
54
 
55
    ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
56
    return (valid);
57
}
58
 
59
void QmDialogChangeTeamNumber::updateSourceName(int team)
60
{
61
    sourceTeam = team;
62
    g_record( team, &team_buf_source );
63
    ui->sourceName->setText( team_buf_source.name );
64
    checkValidOpr();
65
}
66
 
67
void QmDialogChangeTeamNumber::updateTargetName(int team)
68
{
69
    targetTeam = team;
70
    g_record( team, &team_buf_target );
71
    ui->targetName->setText( team_buf_target.name );
72
    checkValidOpr();
73
}
74
 
75
void QmDialogChangeTeamNumber::accept ()
76
{
77
    //qDebug("QmDialogChangeTeamNumber::accept");
78
 
79
    //
80
    //  Should  not get here, but just in case
81
    //
82
    if (!checkValidOpr())
83
    {
302 david 84
        return;
85
    }
86
 
87
    //
88
    //  Get team records
89
    //
90
    g_record( ui->sourceTeam->value(), &team_buf_source );
91
 
92
    //  Swap Records
93
    if (ui->swapMode->isChecked())
94
    {
95
        g_record( ui->targetTeam->value(), &team_buf_target );
96
 
97
        put_team_record(ui->targetTeam->value(), &team_buf_source );
98
        put_team_record(ui->sourceTeam->value(), &team_buf_target );
303 david 99
        //qDebug("QmDialogChangeTeamNumber:: Swap Team:%d <-> %d", ui->sourceTeam->value(), ui->targetTeam->value());
100
        MainWindow::showMessage(QString("Swap teams %1 <-> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
101
 
302 david 102
    }
103
    else
104
    {
105
        put_team_record(ui->targetTeam->value(), &team_buf_source );
303 david 106
        //qDebug("QmDialogChangeTeamNumber:: Copy Team:%d -> %d", ui->sourceTeam->value(), ui->targetTeam->value());
302 david 107
        if (ui->eraseSource->isChecked())
108
        {
109
            clr_team( ui->sourceTeam->value(), &team_buf_target );
110
            put_team_record(ui->sourceTeam->value(), &team_buf_target );
303 david 111
            //qDebug("QmDialogChangeTeamNumber:: Erase Team:%d", ui->sourceTeam->value());
112
            MainWindow::showMessage(QString("Move team %1 -> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
302 david 113
        }
303 david 114
        else
115
        {
116
            MainWindow::showMessage(QString("Duplicate team %1 -> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
117
        }
302 david 118
    }
119
 
120
 
121
    //  All the work has been done
303 david 122
    //  Back to the user - calling the parents function will close the dialog
123
    //
302 david 124
    QDialog::accept();
125
}