Subversion Repositories svn1

Rev

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

Rev Author Line No. Line
95 david 1
#include "qmconfclass.h"
174 - 2
#include "qmconfig.h"
95 david 3
#include "ui_qmconfclass.h"
99 david 4
#include    "consts.h"
5
#include    "structs.h"
6
#include    "proto.h"
180 - 7
#include "mainwindow.h"
310 david 8
#include "qmTableWidgetItem.h"
95 david 9
 
286 david 10
#include <QDialogButtonBox>
99 david 11
#include "QTableWidgetItem"
107 david 12
#include "spinboxdelegate.h"
13
#include "timedelegate.h"
111 david 14
#include "textdelegate.h"
180 - 15
#include <QMenu>
99 david 16
 
227 - 17
#define COL_ABR 0
18
#define COL_CLASS 1
19
#define COL_TIME 2
20
#define COL_WINNERS 3
21
#define COL_NE 4
22
#define COL_NE_WINNERS 5
23
#define COL_ST_TOTAL 6
228 - 24
#define COL_ST_VALID 7
25
#define COL_ST_DISQ 8
26
#define COL_ST_NONEQ 9
27
#define COL_ST_VET 10
284 david 28
#define COL_ST_CEV 11
29
#define COL_ST_CNE 12
311 david 30
#define COL_INDEX 13
227 - 31
 
311 david 32
#define COL_COUNT 14
227 - 33
 
311 david 34
 
104 - 35
QmConfClass::QmConfClass(QWidget *parent) :
286 david 36
    QWidget(parent)
95 david 37
{
181 - 38
    populating = false;
312 david 39
    dirty = false;
99 david 40
 
286 david 41
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
42
    verticalLayout->setContentsMargins(0, 0, 0, 0);
43
 
44
    QGroupBox *groupBox = new QGroupBox("Class");
45
    verticalLayout->addWidget(groupBox);
46
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
47
    tableWidget = new QTableWidget(groupBox);
48
    tableWidget->setAlternatingRowColors(true);
49
    tableWidget->setRowCount(config.num_class + 1);
50
    tableWidget->setColumnCount(COL_COUNT);
51
    tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
52
    tableWidget->horizontalHeader()->setVisible(true);
53
    tableWidget->horizontalHeader()->setDefaultSectionSize(70);
54
    tableWidget->horizontalHeader()->setHighlightSections(true);
290 david 55
    //tableWidget->horizontalHeader()->setStretchLastSection(true);
286 david 56
    tableWidget->verticalHeader()->setVisible(true);
57
    tableWidget->verticalHeader()->setDefaultSectionSize(20);
58
    //tableWidget->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding );
59
    //tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
60
    verticalLayout2->addWidget(tableWidget);
61
 
62
    //QSpacerItem *verticalSpacer1;
63
    //verticalSpacer1 = new QSpacerItem(0, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
64
    //verticalLayout2->addItem(verticalSpacer1);
65
 
66
    QHBoxLayout *horizontalLayout;
67
    horizontalLayout = new QHBoxLayout();
68
    horizontalLayout->setContentsMargins(0, 0, 5, 5);
69
    verticalLayout->addLayout(horizontalLayout);
70
 
71
    QDialogButtonBox *buttonBox = new QDialogButtonBox();
72
    pushButtonRestore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
73
    pushButtonSave = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
74
    horizontalLayout->addWidget(buttonBox);
75
 
76
 
77
    connect(pushButtonSave, SIGNAL(clicked(bool)), this, SLOT(save()) );
78
    connect(pushButtonRestore, SIGNAL(clicked(bool)), this, SLOT(cancel()) );
79
 
109 david 80
    QStringList labels;
228 - 81
    labels << "Abr" << "Full Name" << "Start Time" << "Winners" << "NE" << "NE Winners";
109 david 82
 
311 david 83
    labels << "Total" << "Valid" <<"Disqual" << "NonEq" << "VetCheck" << "Comp Ev" << " Comp NE";
107 david 84
 
311 david 85
    labels << "Index";
86
 
87
    tableWidget->setHorizontalHeaderLabels(labels);
88
 
286 david 89
    connect(tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
90
    connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int,int)));
180 - 91
 
107 david 92
    /*
93
    **  Setup delegated for specialised editing
94
    */
286 david 95
    tableWidget->setItemDelegateForColumn(COL_ABR, new textDelegate(2));
96
    tableWidget->setItemDelegateForColumn(COL_CLASS, new textDelegate(LEN_CLASS_NAME));
97
    tableWidget->setItemDelegateForColumn(COL_TIME, new timeDelegate());
98
    tableWidget->setItemDelegateForColumn(COL_WINNERS, new SpinBoxDelegate(0,50));
99
    tableWidget->setItemDelegateForColumn(COL_NE_WINNERS, new SpinBoxDelegate(0,50));
312 david 100
}
107 david 101
 
312 david 102
/*----------------------------------------------------------------------------
103
** FUNCTION           : showEvent 
104
**
105
** DESCRIPTION        : Called when the page is shown
106
**                      Used to refresh the contents of the display as well
107
**                      as show them for the first time
108
**
109
----------------------------------------------------------------------------*/
110
 
111
void QmConfClass::showEvent ( QShowEvent * event )
112
{
113
    //qDebug("populate::showEvent");
114
    if ( ! event->spontaneous() && !dirty )
115
    {
116
        populate();
117
    }
311 david 118
}
180 - 119
 
311 david 120
/*----------------------------------------------------------------------------
121
** FUNCTION           : populate
122
**
123
** DESCRIPTION        : Populate the display with information
124
**
125
----------------------------------------------------------------------------*/
180 - 126
 
104 - 127
void QmConfClass::populate(void)
99 david 128
{
311 david 129
    bool    reportDataLoaded = false;
130
    t_class_summary data;
131
 
181 - 132
    populating = true;
310 david 133
    tableWidget->clearContents();
313 david 134
    tableWidget->setRowCount(0);
310 david 135
    tableWidget->setSortingEnabled(false);
311 david 136
 
137
    /*
138
    ** Load Report Data if we can
139
    */
140
    if( load_report_data() )
99 david 141
    {
311 david 142
        calc_class_summary( & data );
143
        reportDataLoaded = true;
144
    }
105 - 145
 
311 david 146
    /*
147
    **  Add all the information
148
    */
149
    int ii = 0;
150
    int entryIndex = 0;
151
    for ( ii = 0; ii < MAX_CLASS; ii++)
152
    {
153
        if ( config.team_class[ii].abr[0] )
111 david 154
        {
311 david 155
            // Keep the config item index entry
156
            //  Will need it when we write stiff out
313 david 157
            tableWidget->setRowCount(tableWidget->rowCount() + 1);
158
 
311 david 159
            tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(ii));
160
 
368 david 161
            tableWidget->setItem(entryIndex, COL_ABR,        new qmTwiEditString(config.team_class[ii].abr ));
162
            tableWidget->setItem(entryIndex, COL_CLASS,      new qmTwiEditString(config.team_class[ii].full_name ));
311 david 163
 
111 david 164
            QTableWidgetItem *item;
165
            item = new QTableWidgetItem();
166
            item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
311 david 167
            tableWidget->setItem(entryIndex, COL_TIME, item);
107 david 168
 
313 david 169
            tableWidget->setItem(entryIndex, COL_WINNERS,    new qmTwiEditNumber(config.class_winners[ii]));
170
            tableWidget->setItem(entryIndex, COL_NE,         new qmTwiEditFlag("",config.nonequestrian_class == 1 + ii));
171
            tableWidget->setItem(entryIndex, COL_NE_WINNERS, new qmTwiEditNumber(config.class_ne_winners[ii]));
181 - 172
 
311 david 173
            if (reportDataLoaded)
174
            {
175
                tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.teamclass[ii+1].total) );
176
                tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.teamclass[ii+1].valid) );
177
                tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.teamclass[ii+1].disqualified));
178
                tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.teamclass[ii+1].non_equestrian));
179
                tableWidget->setItem(entryIndex,COL_ST_VET,   new qmTwiNumber(data.teamclass[ii+1].vet_check));
180
                tableWidget->setItem(entryIndex,COL_ST_CEV,   new qmTwiNumber(data.teamclass[ii+1].valid_ev));
181
                tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.teamclass[ii+1].valid_ne));
182
            }
183
            entryIndex++;
111 david 184
        }
99 david 185
    }
311 david 186
 
187
    //  Insert Totals
188
    //      Flag that items on this this row is not to be sorted - or at least 
189
    //      sorted at the end
190
    //
191
    if (reportDataLoaded)
192
    {
313 david 193
        tableWidget->setRowCount(tableWidget->rowCount() + 1);
311 david 194
        tableWidget->setItem(entryIndex,COL_ABR,      new qmTwiString("Totals", 1));
324 david 195
 
368 david 196
        tableWidget->setItem(entryIndex, COL_CLASS,         new qmTwiString("",1));
197
        tableWidget->setItem(entryIndex, COL_TIME,          new qmTwiString("",1));
198
        tableWidget->setItem(entryIndex, COL_WINNERS,       new qmTwiString("",1));
199
        tableWidget->setItem(entryIndex, COL_NE,            new qmTwiString("",1));
200
        tableWidget->setItem(entryIndex, COL_NE_WINNERS,    new qmTwiString("",1));
201
        tableWidget->setItem(entryIndex, COL_INDEX,         new qmTwiString("",1));
324 david 202
 
311 david 203
        tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.total.total, 1));
204
        tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.total.valid, 1));
205
        tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.total.disqualified, 1));
206
        tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.total.non_equestrian, 1));
207
        tableWidget->setItem(entryIndex,COL_ST_VET,   new qmTwiNumber(data.total.vet_check, 1));
208
        tableWidget->setItem(entryIndex,COL_ST_CEV,   new qmTwiNumber(data.total.valid_ev, 1));
209
        tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.total.valid_ne, 1));
368 david 210
 
211
        // Debug
212
        // tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(5,2));
213
 
311 david 214
    }
215
 
368 david 216
    tableWidget->sortByColumn ( COL_INDEX, Qt::AscendingOrder );
217
    tableWidget->setSortingEnabled(true);
311 david 218
    tableWidget->resizeColumnsToContents();
219
    tableWidget->resizeRowsToContents();
220
 
181 - 221
    updateChanged(false);
222
    populating = false;
99 david 223
}
224
 
104 - 225
void QmConfClass::save(void)
99 david 226
{
104 - 227
    /*
228
    **    Copy original data
229
    */
176 - 230
    QmConfig newcfg(config);
104 - 231
 
232
    /*
233
    **  Extract the data from the Widgets
312 david 234
    **  Trap: The Class info is cross ref by index into the table
235
    **        Thus we need to maintain the order in the config.
104 - 236
    */
311 david 237
    for (int entryIndex = 0; entryIndex < tableWidget->rowCount(); entryIndex++)
104 - 238
    {
310 david 239
 
240
        // Check that this is a real Entry or the 'Totals' header
324 david 241
        //      Real rows have a COL_INDEX entry that is not empty
310 david 242
        //
311 david 243
        QTableWidgetItem *item = tableWidget->item ( entryIndex, COL_INDEX );
244
        if (! item)
310 david 245
        {
314 david 246
            //qDebug("Ignore row:%d", entryIndex);
310 david 247
            continue;
248
        }
324 david 249
        if ( item->text().length() == 0)
250
        {
251
            //qDebug("Ignore empty row:%d", entryIndex);
252
            continue;
253
        }
311 david 254
        int ii = item->text().toInt();
314 david 255
        //qDebug("Processing: %d", ii);
310 david 256
 
312 david 257
        /*
313 david 258
        ** This is a new entry - allocate a new index 
259
        **  Scan the entire available space looking for the first empty slot
312 david 260
        */
261
        if (ii < 0)
311 david 262
        {
313 david 263
            for (ii = 0; ii < MAX_CLASS ; ii++)
264
            {
265
                if (newcfg.team_class[ii].abr[0] == 0)
266
                {
267
                    break;
268
                }
269
            }
312 david 270
        }
271
 
272
        if (ii >= MAX_CLASS )
273
        {
274
            qDebug("Ignore row:%d. Class out of range", entryIndex);
311 david 275
            continue;
276
        }
277
 
278
        item = tableWidget->item ( entryIndex, COL_ABR );
111 david 279
        if ( item )
280
        {
281
            strncpy(newcfg.team_class[ii].abr, qPrintable(item->text()), sizeof(newcfg.team_class[ii].abr)-1);
282
        }
283
        else
284
        {
285
            *newcfg.team_class[ii].abr = 0;
286
        }
104 - 287
 
310 david 288
        item = tableWidget->item ( entryIndex, COL_CLASS );
111 david 289
        if ( item )
290
        {
291
            strncpy(newcfg.team_class[ii].full_name, qPrintable(item->text()), sizeof(newcfg.team_class[ii].full_name)-1);
292
        }
293
        else
294
        {
295
            *newcfg.team_class[ii].full_name = 0;
296
        }
108 david 297
 
310 david 298
        item = tableWidget->item( entryIndex, COL_TIME );
111 david 299
        if ( item )
300
        {
195 david 301
            QVariant data = item->data(Qt::EditRole);
302
            if (data.isValid())
303
            {
304
                newcfg.team_class[ii].start = QTime(0,0,0).secsTo(item->data(Qt::EditRole).toTime());
305
            }
306
            else
307
            {
308
                newcfg.team_class[ii].start = -1;
309
            }
111 david 310
        }
311
        else
312
        {
195 david 313
            newcfg.team_class[ii].start = -1;
111 david 314
        }
315
 
310 david 316
        item = tableWidget->item( entryIndex, COL_WINNERS );
111 david 317
        if ( item )
318
        {
319
            newcfg.class_winners[ii] = item->data(Qt::EditRole).toInt();
320
        }
321
        else
322
        {
323
            newcfg.class_winners[ii] = 0;
324
        }
227 - 325
 
310 david 326
        item = tableWidget->item( entryIndex, COL_NE );
181 - 327
        if ( item )
328
        {
329
            if ( item->checkState() == Qt::Checked)
330
            {
331
                newcfg.nonequestrian_class = ii;
332
                strncpy(newcfg.nonequestrian_class_abr, newcfg.team_class[ii].abr, sizeof(newcfg.team_class[ii].abr)-1);
333
            }
334
        }
227 - 335
 
310 david 336
        item = tableWidget->item( entryIndex, COL_NE_WINNERS );
227 - 337
        if ( item )
338
        {
339
            newcfg.class_ne_winners[ii] = item->data(Qt::EditRole).toInt();
340
        }
341
        else
342
        {
343
            newcfg.class_ne_winners[ii] = 0;
344
        }
104 - 345
    }
346
 
181 - 347
    // Validate the data
348
    try
104 - 349
    {
181 - 350
        MainWindow::showMessage( "Saving Config");
104 - 351
 
181 - 352
        /*
353
         **  Now do the Class definitions
354
         */
355
 
356
        for( int i = 0; i < MAX_CLASS; i++ )
104 - 357
        {
181 - 358
            compact( newcfg.team_class[i].abr );
359
            compact( newcfg.team_class[i].full_name );
104 - 360
        }
181 - 361
 
362
        for( int i = 0; i < MAX_CLASS; i++ )
104 - 363
        {
181 - 364
            if( ( newcfg.team_class[i].abr[0] == '\0' ) != ( newcfg.team_class[i].full_name[0] == '\0' ) )
365
            {
366
                throw( "Configuration error. Class without description" );
367
 
368
            }
369
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.team_class[i].start < 0L )
370
            {
371
                throw( "Configuration error. Bad start time on class" );
372
 
373
            }
104 - 374
        }
375
 
313 david 376
        //  Calculate new max number of classes
377
        //      Scan from the end looking for the last one used
378
        //
379
        for (int i = MAX_CLASS-1; i >= 0; i--)
380
        {
381
            if (newcfg.team_class[i].abr[0])
382
            {
314 david 383
                //qDebug("num_class:%d -> %d", newcfg.num_class, 1+i);
313 david 384
                newcfg.num_class = 1 + i;
385
                break;
386
            }
387
        }
104 - 388
 
181 - 389
        for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
390
            if( newcfg.team_class[i].full_name[0] )
391
            {
313 david 392
                qDebug( "Configuration error: Missing Class name. Gaps not allowed" );
181 - 393
            }
394
 
395
        if( newcfg.num_class == 0 )
104 - 396
        {
181 - 397
            throw( "Error: No categories defined" );
398
 
104 - 399
        }
400
 
312 david 401
        /*
402
        ** Test for duplicate abbreviations 
403
        ** I know its a slow agorithm, but its only a small set 
404
        */
405
        for( int i = 0; i < MAX_CLASS; i++ )
406
        {
407
            if (newcfg.team_class[i].abr[0] != '\0')
408
            {
409
                for (int j = i+1; j < MAX_CLASS; j++)
410
                {
411
                    if (newcfg.team_class[j].abr[0] != '\0')
412
                    {
413
                        if (    newcfg.team_class[i].abr[0] == newcfg.team_class[j].abr[0]
414
                             && newcfg.team_class[i].abr[1] == newcfg.team_class[j].abr[1]
415
                            )
416
                        {
417
                            qDebug("Duplicate abr: %s", newcfg.team_class[i].abr);
418
                            throw( "Error: Duplicate abbreviations detected");
419
                        }
420
                    }
421
                }
422
            }
423
        }
424
 
425
        /*
426
        ** Sanity Test
427
        */
181 - 428
        newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
429
        if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
430
            MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
314 david 431
        //qDebug("NE Index is: %d", newcfg.nonequestrian_class );
181 - 432
        /*
433
        **  Sanity test of the data
434
        */
435
        for( int i = 0; i < MAX_CLASS; i++ )
436
        {
437
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
438
            {
312 david 439
                if (newcfg.nonequestrian_class != i+1)
440
                {
441
                    MainWindow::showMessage(QString("Warning: Class without winners:")+ newcfg.team_class[i].abr); 
442
                }
181 - 443
            }
111 david 444
        }
445
 
227 - 446
        /*
447
        ** Cannot mix winners for NE class and NE Winners for each class
448
        */
449
        if (newcfg.nonequestrian_class)
450
        {
451
            newcfg.class_ne_winners_by_class = false;
452
            for( int i = 0; i < MAX_CLASS; i++ )
453
            {
228 - 454
                if ( newcfg.class_ne_winners[i])
455
                {
456
                    newcfg.class_ne_winners_by_class = true;
457
                    break;
458
                }
227 - 459
            }
460
            if (newcfg.class_winners[newcfg.nonequestrian_class - 1] && newcfg.class_ne_winners_by_class )
461
            {
462
                MainWindow::showMessage( QString("Should not mix NE winners by each class and by NE Class"));
463
                //throw( "Error: Cannot mix NE winners by each class and by NE Class" );
464
            }
465
        }
466
 
467
 
104 - 468
        config = newcfg;
176 - 469
        config.write_config();
181 - 470
        updateChanged(false);
471
 
312 david 472
        // Force re-populate so that the index field is now correct
473
        populate();
474
 
475
 
104 - 476
    }
313 david 477
    catch (const char * str )
181 - 478
    {
479
        MainWindow::showMessage(str);
480
    }
104 - 481
 
99 david 482
}
483
 
104 - 484
void QmConfClass::cancel(void)
99 david 485
{
486
    populate();
487
}
488
 
104 - 489
QmConfClass::~QmConfClass()
95 david 490
{
286 david 491
 
95 david 492
}
493
 
180 - 494
void QmConfClass::ctxMenu(const QPoint & pos)
495
{
314 david 496
    //qDebug("Context Menu");
180 - 497
    QMenu *menu = new QMenu;
312 david 498
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
499
 
500
    /*
313 david 501
    **      Determine if we can delete an item
502
    **          Can delete a category we added in this session
503
    **          Can delete one if it has no teams using it.
312 david 504
    */
286 david 505
    QTableWidgetItem *item = tableWidget->itemAt(pos);
180 - 506
    if (item)
507
    {
312 david 508
        int row = item->row();
314 david 509
        //qDebug("Item is at row:%d", row);
312 david 510
        QTableWidgetItem *indexItem = tableWidget->item ( row, COL_INDEX );
511
        if (indexItem)
512
        {
513
            int index = indexItem->text().toInt();
314 david 514
            //qDebug("Item is at row:%d, Index: %d", row, index);
312 david 515
            if (index < 0)
516
            {
313 david 517
                menu->addAction(tr("Delete Newly added Category"), this, SLOT(ctxMenuDeleteRow())); 
312 david 518
            }
313 david 519
            else
520
            {
521
                QTableWidgetItem *itemTotalCount = tableWidget->item ( row, COL_ST_TOTAL );
522
                if (itemTotalCount)
523
                {
524
                    int count = itemTotalCount->text().toInt();
525
                    if (count == 0)
526
                    {
527
                        menu->addAction(tr("Delete Category - its not used"), this, SLOT(ctxMenuDeleteRow()));  
528
                    }
529
                }
530
 
531
            }
312 david 532
        }
180 - 533
    }
313 david 534
    menu->exec(tableWidget->mapToGlobal(pos));
180 - 535
}
536
 
537
void QmConfClass::ctxMenuDeleteRow(void)
538
{
312 david 539
    //
540
    //  Assume that if the menu was shown, then we can delete it
541
    // 
286 david 542
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
313 david 543
    //tableWidget->removeCellWidget(tableWidget->currentRow (), COL_ABR);
544
    //tableWidget->removeRow(tableWidget->currentRow ());
545
    tableWidget->item(tableWidget->currentRow (), COL_ABR)->setText("");
546
    tableWidget->item(tableWidget->currentRow (), COL_CLASS)->setText("");
314 david 547
    tableWidget->hideRow(tableWidget->currentRow ());
189 - 548
    updateChanged(true);
180 - 549
}
550
 
551
void QmConfClass::ctxMenuAddRow(void)
552
{
313 david 553
    tableWidget->setSortingEnabled(false);
286 david 554
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
324 david 555
 
556
    /*
557
    **  Insert non-editable fields in the status part of the table
558
    */
312 david 559
    tableWidget->setItem(tableWidget->rowCount() - 1, COL_INDEX, new qmTwiNumber(-1));
324 david 560
    for (int ii= COL_ST_TOTAL; ii < COL_INDEX; ii++)
561
    {
562
        tableWidget->setItem(tableWidget->rowCount() - 1, ii, new qmTwiString(""));
563
    }
180 - 564
}
565
 
181 - 566
void QmConfClass::cellChanged(int row,int col)
567
{
568
    if ( populating )
569
        return;
312 david 570
    if (col == COL_INDEX)
571
        return;
572
 
573
    updateChanged(true); 
181 - 574
    populating = true;
575
    //qDebug("Cell changed: %d, %d", row, col);
227 - 576
    if (col == COL_NE)
181 - 577
    {
286 david 578
        for (int ii = 0; ii < tableWidget->rowCount(); ii++)
181 - 579
        {
286 david 580
            QTableWidgetItem *item = tableWidget->item(ii, COL_NE);
181 - 581
            if (item)
582
            {
583
                item->setCheckState(ii == row ? Qt::Checked : Qt::Unchecked);
584
            }
585
        }
586
    }
587
    populating = false;
588
}
589
 
590
void QmConfClass::updateChanged(bool newDirty)
591
{
592
    if (newDirty != dirty)
593
    {
594
        dirty = newDirty;
595
        if (dirty)
596
        {
286 david 597
            pushButtonSave->setEnabled(true);
598
            pushButtonSave->setStyleSheet("background-color: rgb(255, 0, 0);");
181 - 599
        }
600
        else
601
        {
286 david 602
            pushButtonSave->setEnabled(false);
603
            pushButtonSave->setStyleSheet("");
181 - 604
        }
605
    }
606
}
607
 
104 - 608
void QmConfClass::changeEvent(QEvent *e)
95 david 609
{
610
    QWidget::changeEvent(e);
611
    switch (e->type()) {
286 david 612
 
95 david 613
    default:
614
        break;
615
    }
616
}