Subversion Repositories svn1

Rev

Rev 311 | Rev 313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 311 Rev 312
Line 34... Line 34...
34
 
34
 
35
QmConfClass::QmConfClass(QWidget *parent) :
35
QmConfClass::QmConfClass(QWidget *parent) :
36
    QWidget(parent)
36
    QWidget(parent)
37
{
37
{
38
    populating = false;
38
    populating = false;
39
    //resize ( 600,400);
39
    dirty = false;
40
 
40
 
41
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
41
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
42
    verticalLayout->setContentsMargins(0, 0, 0, 0);
42
    verticalLayout->setContentsMargins(0, 0, 0, 0);
43
 
43
 
44
    QGroupBox *groupBox = new QGroupBox("Class");
44
    QGroupBox *groupBox = new QGroupBox("Class");
Line 96... Line 96...
96
    tableWidget->setItemDelegateForColumn(COL_ABR, new textDelegate(2));
96
    tableWidget->setItemDelegateForColumn(COL_ABR, new textDelegate(2));
97
    tableWidget->setItemDelegateForColumn(COL_CLASS, new textDelegate(LEN_CLASS_NAME));
97
    tableWidget->setItemDelegateForColumn(COL_CLASS, new textDelegate(LEN_CLASS_NAME));
98
    tableWidget->setItemDelegateForColumn(COL_TIME, new timeDelegate());
98
    tableWidget->setItemDelegateForColumn(COL_TIME, new timeDelegate());
99
    tableWidget->setItemDelegateForColumn(COL_WINNERS, new SpinBoxDelegate(0,50));
99
    tableWidget->setItemDelegateForColumn(COL_WINNERS, new SpinBoxDelegate(0,50));
100
    tableWidget->setItemDelegateForColumn(COL_NE_WINNERS, new SpinBoxDelegate(0,50));
100
    tableWidget->setItemDelegateForColumn(COL_NE_WINNERS, new SpinBoxDelegate(0,50));
-
 
101
}
101
 
102
 
-
 
103
/*----------------------------------------------------------------------------
-
 
104
** FUNCTION           : showEvent 
-
 
105
**
-
 
106
** DESCRIPTION        : Called when the page is shown
-
 
107
**                      Used to refresh the contents of the display as well
-
 
108
**                      as show them for the first time
-
 
109
**
-
 
110
----------------------------------------------------------------------------*/
-
 
111
 
-
 
112
void QmConfClass::showEvent ( QShowEvent * event )
-
 
113
{
-
 
114
    //qDebug("populate::showEvent");
-
 
115
    if ( ! event->spontaneous() && !dirty )
-
 
116
    {
102
    populate();
117
        populate();
-
 
118
    }
103
}
119
}
104
 
120
 
105
/*----------------------------------------------------------------------------
121
/*----------------------------------------------------------------------------
106
** FUNCTION           : populate
122
** FUNCTION           : populate
107
**
123
**
Line 204... Line 220...
204
    */
220
    */
205
    QmConfig newcfg(config);
221
    QmConfig newcfg(config);
206
 
222
 
207
    /*
223
    /*
208
    **  Extract the data from the Widgets
224
    **  Extract the data from the Widgets
-
 
225
    **  Trap: The Class info is cross ref by index into the table
-
 
226
    **        Thus we need to maintain the order in the config.
209
    */
227
    */
210
    for (int entryIndex = 0; entryIndex < tableWidget->rowCount(); entryIndex++)
228
    for (int entryIndex = 0; entryIndex < tableWidget->rowCount(); entryIndex++)
211
    {
229
    {
212
 
230
 
213
        // Check that this is a real Entry or the 'Totals' header
231
        // Check that this is a real Entry or the 'Totals' header
Line 220... Line 238...
220
            continue;
238
            continue;
221
        }
239
        }
222
        int ii = item->text().toInt();
240
        int ii = item->text().toInt();
223
        qDebug("Processing: %d", ii);
241
        qDebug("Processing: %d", ii);
224
 
242
 
-
 
243
        /*
-
 
244
        ** This is a new entry - allocate a new index
-
 
245
        */
225
        if (ii >= MAX_CLASS || ii < 0)
246
        if (ii < 0)
226
        {
247
        {
-
 
248
            ii = newcfg.num_class;
-
 
249
            newcfg.num_class++;
-
 
250
        }
-
 
251
 
-
 
252
        if (ii >= MAX_CLASS )
-
 
253
        {
227
            qDebug("Ignore row:%d. Class out of rande", entryIndex);
254
            qDebug("Ignore row:%d. Class out of range", entryIndex);
228
            continue;
255
            continue;
229
        }
256
        }
230
 
257
 
231
        item = tableWidget->item ( entryIndex, COL_ABR );
258
        item = tableWidget->item ( entryIndex, COL_ABR );
232
        if ( item )
259
        if ( item )
Line 342... Line 369...
342
        {
369
        {
343
            throw( "Error: No categories defined" );
370
            throw( "Error: No categories defined" );
344
 
371
 
345
        }
372
        }
346
 
373
 
-
 
374
        /*
-
 
375
        ** Test for duplicate abbreviations 
-
 
376
        ** I know its a slow agorithm, but its only a small set 
-
 
377
        */
-
 
378
        for( int i = 0; i < MAX_CLASS; i++ )
-
 
379
        {
-
 
380
            if (newcfg.team_class[i].abr[0] != '\0')
-
 
381
            {
-
 
382
                for (int j = i+1; j < MAX_CLASS; j++)
-
 
383
                {
-
 
384
                    if (newcfg.team_class[j].abr[0] != '\0')
-
 
385
                    {
-
 
386
                        if (    newcfg.team_class[i].abr[0] == newcfg.team_class[j].abr[0]
-
 
387
                             && newcfg.team_class[i].abr[1] == newcfg.team_class[j].abr[1]
-
 
388
                            )
-
 
389
                        {
-
 
390
                            qDebug("Duplicate abr: %s", newcfg.team_class[i].abr);
-
 
391
                            throw( "Error: Duplicate abbreviations detected");
-
 
392
                        }
-
 
393
                    }
-
 
394
                }
-
 
395
            }
-
 
396
        }
-
 
397
 
-
 
398
        /*
-
 
399
        ** Sanity Test
-
 
400
        */
347
        newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
401
        newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
348
        if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
402
        if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
349
            MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
403
            MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
350
 
-
 
-
 
404
        qDebug("NE Index is: %d", newcfg.nonequestrian_class );
351
        /*
405
        /*
352
        **  Sanity test of the data
406
        **  Sanity test of the data
353
        */
407
        */
354
        for( int i = 0; i < MAX_CLASS; i++ )
408
        for( int i = 0; i < MAX_CLASS; i++ )
355
        {
409
        {
356
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
410
            if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
357
            {
411
            {
358
 
-
 
-
 
412
                if (newcfg.nonequestrian_class != i+1)
-
 
413
                {
359
                MainWindow::showMessage( QString("Warning: Class without winners:") + newcfg.team_class[i].abr );
414
                    MainWindow::showMessage(QString("Warning: Class without winners:")+ newcfg.team_class[i].abr); 
-
 
415
                }
360
            }
416
            }
361
        }
417
        }
362
 
418
 
363
        /*
419
        /*
364
        ** Cannot mix winners for NE class and NE Winners for each class
420
        ** Cannot mix winners for NE class and NE Winners for each class
Line 384... Line 440...
384
 
440
 
385
        config = newcfg;
441
        config = newcfg;
386
        config.write_config();
442
        config.write_config();
387
        updateChanged(false);
443
        updateChanged(false);
388
 
444
 
-
 
445
        // Force re-populate so that the index field is now correct
-
 
446
        populate();
-
 
447
 
-
 
448
 
389
    }
449
    }
390
    catch (const char * str )
450
    catch (const QString str )
391
    {
451
    {
392
        MainWindow::showMessage(str);
452
        MainWindow::showMessage(str);
393
    }
453
    }
394
 
454
 
395
}
455
}
Line 406... Line 466...
406
 
466
 
407
void QmConfClass::ctxMenu(const QPoint & pos)
467
void QmConfClass::ctxMenu(const QPoint & pos)
408
{
468
{
409
    qDebug("Context Menu");
469
    qDebug("Context Menu");
410
    QMenu *menu = new QMenu;
470
    QMenu *menu = new QMenu;
411
    QTableWidgetItem *item = tableWidget->itemAt(pos);
-
 
412
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
471
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
-
 
472
 
-
 
473
    /*
-
 
474
    **      Determine if we can delete an item 
-
 
475
    **      Do NOT delete items, unless thay have been added in this session
-
 
476
    **      Once a class entry has been made it may be cross referenecd from
-
 
477
    **      team data.
-
 
478
    */
-
 
479
    QTableWidgetItem *item = tableWidget->itemAt(pos);
413
    if (item)
480
    if (item)
414
    {
481
    {
-
 
482
        int row = item->row();
-
 
483
        qDebug("Item is at row:%d", row);
-
 
484
        QTableWidgetItem *indexItem = tableWidget->item ( row, COL_INDEX );
-
 
485
        if (indexItem)
-
 
486
        {
-
 
487
            int index = indexItem->text().toInt();
-
 
488
            qDebug("Item is at row:%d, Index: %d", row, index);
-
 
489
            if (index < 0)
-
 
490
            {
415
        menu->addAction(tr("Delete Category"), this, SLOT(ctxMenuDeleteRow()));
491
                menu->addAction(tr("Delete Category"), this, SLOT(ctxMenuDeleteRow())); 
-
 
492
            }
-
 
493
        }
416
    }
494
    }
417
   menu->exec(tableWidget->mapToGlobal(pos));
495
   menu->exec(tableWidget->mapToGlobal(pos));
418
 
496
 
419
}
497
}
420
 
498
 
421
void QmConfClass::ctxMenuDeleteRow(void)
499
void QmConfClass::ctxMenuDeleteRow(void)
422
{
500
{
-
 
501
    //
-
 
502
    //  Assume that if the menu was shown, then we can delete it
-
 
503
    // 
423
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
504
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
424
    tableWidget->removeRow(tableWidget->currentRow ());
505
    tableWidget->removeRow(tableWidget->currentRow ());
425
    updateChanged(true);
506
    updateChanged(true);
426
}
507
}
427
 
508
 
428
void QmConfClass::ctxMenuAddRow(void)
509
void QmConfClass::ctxMenuAddRow(void)
429
{
510
{
430
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
511
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
-
 
512
    tableWidget->setItem(tableWidget->rowCount() - 1, COL_INDEX, new qmTwiNumber(-1));
431
}
513
}
432
 
514
 
433
void QmConfClass::cellChanged(int row,int col)
515
void QmConfClass::cellChanged(int row,int col)
434
{
516
{
435
    if ( populating )
517
    if ( populating )
436
        return;
518
        return;
-
 
519
    if (col == COL_INDEX)
-
 
520
        return;
-
 
521
 
437
    updateChanged(true);
522
    updateChanged(true); 
438
    populating = true;
523
    populating = true;
439
    //qDebug("Cell changed: %d, %d", row, col);
524
    //qDebug("Cell changed: %d, %d", row, col);
440
    if (col == COL_NE)
525
    if (col == COL_NE)
441
    {
526
    {
442
        for (int ii = 0; ii < tableWidget->rowCount(); ii++)
527
        for (int ii = 0; ii < tableWidget->rowCount(); ii++)