Subversion Repositories svn1-original

Rev

Rev 307 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
306 david 1
#include "qmdialogchangeteamnumber.h"
2
#include "ui_qmdialogchangeteamnumber.h"
307 david 3
#include "mainwindow.h"
308 david 4
#include <QPushButton>
306 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);
307 david 17
    sourceTeam = 0;
306 david 18
 
19
    ui->targetTeam->setMinimum(config.min_team);
20
    ui->targetTeam->setMaximum(config.max_team);
21
    ui->targetTeam->setValue(0);
307 david 22
    targetTeam = 0;
306 david 23
 
308 david 24
    checkValidOpr(0);
307 david 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)) );
308 david 29
    connect(ui->onlyNames, SIGNAL(stateChanged(int)), this, SLOT(checkValidOpr(int)) );
30
    connect(ui->onlyTimes, SIGNAL(stateChanged(int)), this, SLOT(checkValidOpr(int)) );
31
    connect(ui->copyMode, SIGNAL(clicked(bool)), this, SLOT(checkValidOpr(bool)) );
32
    connect(ui->swapMode, SIGNAL(clicked(bool)), this, SLOT(checkValidOpr(bool)) );
33
    connect(ui->moveMode, SIGNAL(clicked(bool)), this, SLOT(checkValidOpr(bool)) );
306 david 34
}
35
 
36
QmDialogChangeTeamNumber::~QmDialogChangeTeamNumber()
37
{
38
    delete ui;
39
}
40
 
308 david 41
/*----------------------------------------------------------------------------
42
** FUNCTION           : checkValidOpr
43
**
44
** DESCRIPTION        : Check that the operation looks valid. Make
45
**                      sure that the user has entered some data
46
**
47
----------------------------------------------------------------------------*/
48
 
49
bool QmDialogChangeTeamNumber::checkValidOpr(int ignore)
306 david 50
{
307 david 51
    bool valid = true;
308 david 52
    qDebug("QmDialogChangeTeamNumber::checkValidOpr");
306 david 53
 
307 david 54
    //  Ensure that the user has entered something
55
    //
56
    if ( sourceTeam == 0 || targetTeam == 0 )
57
    {
58
        valid = false;
59
    }
306 david 60
 
61
    //  Can't move or copy to myself
62
    //
63
    if ( ui->sourceTeam->value() == ui->targetTeam->value() )
64
    {
307 david 65
        valid = false;
66
    }
67
 
308 david 68
    // Can't have both OnlyNames and onlyTimes set
69
    if (ui->onlyNames->isChecked() && ui->onlyTimes->isChecked())
70
    {
71
        valid = false;
72
    }
73
 
307 david 74
    ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
75
    return (valid);
76
}
77
 
308 david 78
/*----------------------------------------------------------------------------
79
** FUNCTION           : updateSourceName 
80
**
81
** DESCRIPTION        : This method is wired to the team number control
82
**                      It will read in the team data and display it
83
**
84
----------------------------------------------------------------------------*/
85
 
307 david 86
void QmDialogChangeTeamNumber::updateSourceName(int team)
87
{
88
    sourceTeam = team;
89
    g_record( team, &team_buf_source );
90
    ui->sourceName->setText( team_buf_source.name );
308 david 91
    checkValidOpr(0);
307 david 92
}
93
 
94
void QmDialogChangeTeamNumber::updateTargetName(int team)
95
{
96
    targetTeam = team;
97
    g_record( team, &team_buf_target );
98
    ui->targetName->setText( team_buf_target.name );
308 david 99
    checkValidOpr(0);
307 david 100
}
101
 
308 david 102
/*----------------------------------------------------------------------------
103
** FUNCTION           : accept 
104
**
105
** DESCRIPTION        : Overide the QDialogs own function and do the
106
**                      actual processing.
107
** 
108
**                      Assumes that team records have been read in
109
**
110
**
111
----------------------------------------------------------------------------*/
112
 
307 david 113
void QmDialogChangeTeamNumber::accept ()
114
{
308 david 115
    //  Working store
116
    team_type team_buf_work;
117
 
307 david 118
    //qDebug("QmDialogChangeTeamNumber::accept");
119
 
120
    //
121
    //  Should  not get here, but just in case
122
    //
308 david 123
    if (!checkValidOpr(0))
307 david 124
    {
306 david 125
        return;
126
    }
127
 
128
    //
308 david 129
    //  Determine the mode of operation
130
    //      Write out the target team data
131
    //      We always write a target
306 david 132
    //
308 david 133
    if (ui->onlyNames->isChecked() )
134
    {
135
        memcpy(&team_buf_work, &team_buf_source, sizeof(team_buf_work));
136
        memcpy(&team_buf_work.leg, &team_buf_target.leg, sizeof(team_buf_work.leg));
137
        //qDebug("QmDialogChangeTeamNumber:: Copy data: source, target.leg");
138
    }
139
    else if( ui->onlyTimes->isChecked() )
140
    {
141
        memcpy(&team_buf_work, &team_buf_target, sizeof(team_buf_work));
142
        memcpy(&team_buf_work.leg, &team_buf_source.leg, sizeof(team_buf_work.leg));
143
        //qDebug("QmDialogChangeTeamNumber:: Copy data: target, source.leg");
144
    }
145
    else
146
    {
147
        memcpy(&team_buf_work, &team_buf_source, sizeof(team_buf_work));
148
        //qDebug("QmDialogChangeTeamNumber:: Copy data: source, source.leg");
149
    }
150
    put_team_record(ui->targetTeam->value(), &team_buf_work );
306 david 151
 
308 david 152
    //
153
    //  Write out the source team - if swapping
154
    //
306 david 155
    if (ui->swapMode->isChecked())
156
    {
307 david 157
        MainWindow::showMessage(QString("Swap teams %1 <-> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
308 david 158
        if (ui->onlyNames->isChecked() )
159
        {
160
            memcpy(&team_buf_work, &team_buf_target, sizeof(team_buf_work));
161
            memcpy(&team_buf_work.leg, &team_buf_source.leg, sizeof(team_buf_work.leg));
162
            //qDebug("QmDialogChangeTeamNumber:: Swap data: target, source.leg");
163
        }
164
        else if( ui->onlyTimes->isChecked() )
165
        {
166
            memcpy(&team_buf_work, &team_buf_source, sizeof(team_buf_work));
167
            memcpy(&team_buf_work.leg, &team_buf_target.leg, sizeof(team_buf_work.leg));
168
            //qDebug("QmDialogChangeTeamNumber:: Swap data: source, target.leg");
169
        }
170
        else
171
        {
172
            memcpy(&team_buf_work, &team_buf_target, sizeof(team_buf_work));
173
            //qDebug("QmDialogChangeTeamNumber:: Swap data: target");
174
        }
175
        put_team_record(ui->sourceTeam->value(), &team_buf_work );
176
    }
307 david 177
 
308 david 178
    //  Move Mode
179
    //      Have already written the target
180
    //      Need to delete parts of the source
181
    //
182
    if (ui->moveMode->isChecked())
306 david 183
    {
308 david 184
        MainWindow::showMessage(QString("Move team %1 -> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
185
        if (ui->onlyNames->isChecked() )
306 david 186
        {
308 david 187
            clr_team( ui->sourceTeam->value(), &team_buf_work );
188
            memcpy(&team_buf_work.leg, &team_buf_source.leg, sizeof(team_buf_work.leg));
189
            memcpy(&team_buf_source, &team_buf_work, sizeof(team_buf_work));
190
            //qDebug("QmDialogChangeTeamNumber:: Erase data: source, copy target.leg");
306 david 191
        }
308 david 192
        else if( ui->onlyTimes->isChecked() )
193
        {
194
            memset(&team_buf_source.leg,0,sizeof(team_buf_source.leg));
195
            //qDebug("QmDialogChangeTeamNumber:: Erase data: source.leg");
196
        }
307 david 197
        else
198
        {
308 david 199
            clr_team( ui->sourceTeam->value(), &team_buf_source );
200
            //qDebug("QmDialogChangeTeamNumber:: Erase data: source");
307 david 201
        }
308 david 202
 
203
        put_team_record(ui->sourceTeam->value(), &team_buf_source );
204
        MainWindow::showMessage(QString("Move team %1 -> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
306 david 205
    }
206
 
308 david 207
    if (ui->copyMode->isChecked())
208
    {
209
        MainWindow::showMessage(QString("Copy team %1 -> %2").arg(ui->sourceTeam->value()).arg(ui->targetTeam->value()));
210
    }
306 david 211
 
308 david 212
 
306 david 213
    //  All the work has been done
307 david 214
    //  Back to the user - calling the parents function will close the dialog
215
    //
306 david 216
    QDialog::accept();
217
}