Subversion Repositories svn1

Rev

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