Subversion Repositories svn1-original

Rev

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

Rev 316 Rev 317
Line 83... Line 83...
83
    labels << "Total" << "Valid" <<"Disqual" << "NonEq" << "VetCheck" << "Comp Ev" << " Comp NE";
83
    labels << "Total" << "Valid" <<"Disqual" << "NonEq" << "VetCheck" << "Comp Ev" << " Comp NE";
84
 
84
 
85
    labels << "Index";
85
    labels << "Index";
86
 
86
 
87
    tableWidget->setHorizontalHeaderLabels(labels);
87
    tableWidget->setHorizontalHeaderLabels(labels);
88
    tableWidget->resizeColumnsToContents();
-
 
89
 
88
 
90
    connect(tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
89
    connect(tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
91
    connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int,int)));
90
    connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int,int)));
92
 
91
 
93
    /*
92
    /*
Line 130... Line 129...
130
    bool    reportDataLoaded = false;
129
    bool    reportDataLoaded = false;
131
    t_class_summary data;
130
    t_class_summary data;
132
 
131
 
133
    populating = true;
132
    populating = true;
134
    tableWidget->clearContents();
133
    tableWidget->clearContents();
-
 
134
    tableWidget->setRowCount(0);
135
    tableWidget->setSortingEnabled(false);
135
    tableWidget->setSortingEnabled(false);
136
    tableWidget->setRowCount(config.num_class + 1);
-
 
137
 
136
 
138
    /*
137
    /*
139
    ** Load Report Data if we can
138
    ** Load Report Data if we can
140
    */
139
    */
141
    if( load_report_data() )
140
    if( load_report_data() )
Line 153... Line 152...
153
    {
152
    {
154
        if ( config.team_class[ii].abr[0] )
153
        if ( config.team_class[ii].abr[0] )
155
        {
154
        {
156
            // Keep the config item index entry
155
            // Keep the config item index entry
157
            //  Will need it when we write stiff out
156
            //  Will need it when we write stiff out
-
 
157
            tableWidget->setRowCount(tableWidget->rowCount() + 1);
-
 
158
 
158
            tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(ii));
159
            tableWidget->setItem(entryIndex, COL_INDEX, new qmTwiNumber(ii));
159
 
160
 
160
            tableWidget->setItem(entryIndex, COL_ABR, new QTableWidgetItem(config.team_class[ii].abr) );
161
            tableWidget->setItem(entryIndex, COL_ABR,        new qmTwiString(config.team_class[ii].abr) );
161
            tableWidget->setItem(entryIndex, COL_CLASS, new QTableWidgetItem(config.team_class[ii].full_name ));
162
            tableWidget->setItem(entryIndex, COL_CLASS,      new qmTwiString(config.team_class[ii].full_name ));
162
 
163
 
163
            QTableWidgetItem *item;
164
            QTableWidgetItem *item;
164
            item = new QTableWidgetItem();
165
            item = new QTableWidgetItem();
165
            item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
166
            item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
166
            tableWidget->setItem(entryIndex, COL_TIME, item);
167
            tableWidget->setItem(entryIndex, COL_TIME, item);
167
 
168
 
168
            item = new qmTwiEditNumber(config.class_winners[ii]);
169
            tableWidget->setItem(entryIndex, COL_WINNERS,    new qmTwiEditNumber(config.class_winners[ii]));
169
            tableWidget->setItem(entryIndex, COL_WINNERS, item);
-
 
170
 
-
 
171
            item = new QTableWidgetItem();
-
 
172
            item->setCheckState(config.nonequestrian_class == 1 + ii ? Qt::Checked : Qt::Unchecked);
-
 
173
            tableWidget->setItem(entryIndex, COL_NE, item);
170
            tableWidget->setItem(entryIndex, COL_NE,         new qmTwiEditFlag("",config.nonequestrian_class == 1 + ii));
174
 
-
 
175
            item = new qmTwiEditNumber(config.class_ne_winners[ii]);
171
            tableWidget->setItem(entryIndex, COL_NE_WINNERS, new qmTwiEditNumber(config.class_ne_winners[ii]));
176
            tableWidget->setItem(entryIndex, COL_NE_WINNERS, item);
-
 
177
 
172
 
178
            if (reportDataLoaded)
173
            if (reportDataLoaded)
179
            {
174
            {
180
                tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.teamclass[ii+1].total) );
175
                tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.teamclass[ii+1].total) );
181
                tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.teamclass[ii+1].valid) );
176
                tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.teamclass[ii+1].valid) );
Line 193... Line 188...
193
    //      Flag that items on this this row is not to be sorted - or at least 
188
    //      Flag that items on this this row is not to be sorted - or at least 
194
    //      sorted at the end
189
    //      sorted at the end
195
    //
190
    //
196
    if (reportDataLoaded)
191
    if (reportDataLoaded)
197
    {
192
    {
-
 
193
        tableWidget->setRowCount(tableWidget->rowCount() + 1);
198
        tableWidget->setItem(entryIndex,COL_ABR,      new qmTwiString("Totals", 1));
194
        tableWidget->setItem(entryIndex,COL_ABR,      new qmTwiString("Totals", 1));
199
        tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.total.total, 1));
195
        tableWidget->setItem(entryIndex,COL_ST_TOTAL, new qmTwiNumber(data.total.total, 1));
200
        tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.total.valid, 1));
196
        tableWidget->setItem(entryIndex,COL_ST_VALID, new qmTwiNumber(data.total.valid, 1));
201
        tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.total.disqualified, 1));
197
        tableWidget->setItem(entryIndex,COL_ST_DISQ,  new qmTwiNumber(data.total.disqualified, 1));
202
        tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.total.non_equestrian, 1));
198
        tableWidget->setItem(entryIndex,COL_ST_NONEQ, new qmTwiNumber(data.total.non_equestrian, 1));
Line 205... Line 201...
205
        tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.total.valid_ne, 1));
201
        tableWidget->setItem(entryIndex,COL_ST_CNE,   new qmTwiNumber(data.total.valid_ne, 1));
206
    }
202
    }
207
 
203
 
208
    tableWidget->resizeColumnsToContents();
204
    tableWidget->resizeColumnsToContents();
209
    tableWidget->resizeRowsToContents();
205
    tableWidget->resizeRowsToContents();
-
 
206
    tableWidget->sortByColumn ( COL_INDEX, Qt::AscendingOrder );
210
    tableWidget->setSortingEnabled(true);
207
    tableWidget->setSortingEnabled(true);
211
 
208
 
212
    updateChanged(false);
209
    updateChanged(false);
213
    populating = false;
210
    populating = false;
214
}
211
}
Line 239... Line 236...
239
        }
236
        }
240
        int ii = item->text().toInt();
237
        int ii = item->text().toInt();
241
        qDebug("Processing: %d", ii);
238
        qDebug("Processing: %d", ii);
242
 
239
 
243
        /*
240
        /*
244
        ** This is a new entry - allocate a new index
241
        ** This is a new entry - allocate a new index 
-
 
242
        **  Scan the entire available space looking for the first empty slot
245
        */
243
        */
246
        if (ii < 0)
244
        if (ii < 0)
247
        {
245
        {
-
 
246
            for (ii = 0; ii < MAX_CLASS ; ii++)
-
 
247
            {
248
            ii = newcfg.num_class;
248
                if (newcfg.team_class[ii].abr[0] == 0)
-
 
249
                {
249
            newcfg.num_class++;
250
                    break;
-
 
251
                }
-
 
252
            }
250
        }
253
        }
251
 
254
 
252
        if (ii >= MAX_CLASS )
255
        if (ii >= MAX_CLASS )
253
        {
256
        {
254
            qDebug("Ignore row:%d. Class out of range", entryIndex);
257
            qDebug("Ignore row:%d. Class out of range", entryIndex);
Line 351... Line 354...
351
                throw( "Configuration error. Bad start time on class" );
354
                throw( "Configuration error. Bad start time on class" );
352
 
355
 
353
            }
356
            }
354
        }
357
        }
355
 
358
 
356
        newcfg.num_class = 0;
359
        //  Calculate new max number of classes
-
 
360
        //      Scan from the end looking for the last one used
-
 
361
        //
357
        for( int i = 0; i < MAX_CLASS; i++ )
362
        for (int i = MAX_CLASS-1; i >= 0; i--)
-
 
363
        {
358
            if( newcfg.team_class[i].full_name[0] )
364
            if (newcfg.team_class[i].abr[0])
-
 
365
            {
-
 
366
                qDebug("num_class:%d -> %d", newcfg.num_class, 1+i);
359
                newcfg.num_class++;
367
                newcfg.num_class = 1 + i;
-
 
368
                break;
-
 
369
            }
-
 
370
        }
360
 
371
 
361
        for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
372
        for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
362
            if( newcfg.team_class[i].full_name[0] )
373
            if( newcfg.team_class[i].full_name[0] )
363
            {
374
            {
364
                throw( "Configuration error: Missing Class name. Gaps not allowed" );
375
                qDebug( "Configuration error: Missing Class name. Gaps not allowed" );
365
 
-
 
366
            }
376
            }
367
 
377
 
368
        if( newcfg.num_class == 0 )
378
        if( newcfg.num_class == 0 )
369
        {
379
        {
370
            throw( "Error: No categories defined" );
380
            throw( "Error: No categories defined" );
Line 445... Line 455...
445
        // Force re-populate so that the index field is now correct
455
        // Force re-populate so that the index field is now correct
446
        populate();
456
        populate();
447
 
457
 
448
 
458
 
449
    }
459
    }
450
    catch (const QString str )
460
    catch (const char * str )
451
    {
461
    {
452
        MainWindow::showMessage(str);
462
        MainWindow::showMessage(str);
453
    }
463
    }
454
 
464
 
455
}
465
}
Line 469... Line 479...
469
    qDebug("Context Menu");
479
    qDebug("Context Menu");
470
    QMenu *menu = new QMenu;
480
    QMenu *menu = new QMenu;
471
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
481
    menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
472
 
482
 
473
    /*
483
    /*
474
    **      Determine if we can delete an item 
484
    **      Determine if we can delete an item
475
    **      Do NOT delete items, unless thay have been added in this session
485
    **          Can delete a category we added in this session
476
    **      Once a class entry has been made it may be cross referenecd from
486
    **          Can delete one if it has no teams using it.
477
    **      team data.
-
 
478
    */
487
    */
479
    QTableWidgetItem *item = tableWidget->itemAt(pos);
488
    QTableWidgetItem *item = tableWidget->itemAt(pos);
480
    if (item)
489
    if (item)
481
    {
490
    {
482
        int row = item->row();
491
        int row = item->row();
Line 486... Line 495...
486
        {
495
        {
487
            int index = indexItem->text().toInt();
496
            int index = indexItem->text().toInt();
488
            qDebug("Item is at row:%d, Index: %d", row, index);
497
            qDebug("Item is at row:%d, Index: %d", row, index);
489
            if (index < 0)
498
            if (index < 0)
490
            {
499
            {
491
                menu->addAction(tr("Delete Category"), this, SLOT(ctxMenuDeleteRow())); 
500
                menu->addAction(tr("Delete Newly added Category"), this, SLOT(ctxMenuDeleteRow())); 
-
 
501
            }
-
 
502
            else
-
 
503
            {
-
 
504
                QTableWidgetItem *itemTotalCount = tableWidget->item ( row, COL_ST_TOTAL );
-
 
505
                if (itemTotalCount)
-
 
506
                {
-
 
507
                    int count = itemTotalCount->text().toInt();
-
 
508
                    if (count == 0)
-
 
509
                    {
-
 
510
                        menu->addAction(tr("Delete Category - its not used"), this, SLOT(ctxMenuDeleteRow()));  
-
 
511
                    }
-
 
512
                }
-
 
513
 
492
            }
514
            }
493
        }
515
        }
494
    }
516
    }
495
   menu->exec(tableWidget->mapToGlobal(pos));
517
    menu->exec(tableWidget->mapToGlobal(pos));
496
 
-
 
497
}
518
}
498
 
519
 
499
void QmConfClass::ctxMenuDeleteRow(void)
520
void QmConfClass::ctxMenuDeleteRow(void)
500
{
521
{
501
    //
522
    //
502
    //  Assume that if the menu was shown, then we can delete it
523
    //  Assume that if the menu was shown, then we can delete it
503
    // 
524
    // 
504
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
525
    //qDebug ("DELETE ROW: %d", tableWidget->currentRow () );
-
 
526
    //tableWidget->removeCellWidget(tableWidget->currentRow (), COL_ABR);
505
    tableWidget->removeRow(tableWidget->currentRow ());
527
    //tableWidget->removeRow(tableWidget->currentRow ());
-
 
528
    tableWidget->item(tableWidget->currentRow (), COL_ABR)->setText("");
-
 
529
    tableWidget->item(tableWidget->currentRow (), COL_CLASS)->setText("");
506
    updateChanged(true);
530
    updateChanged(true);
507
}
531
}
508
 
532
 
509
void QmConfClass::ctxMenuAddRow(void)
533
void QmConfClass::ctxMenuAddRow(void)
510
{
534
{
-
 
535
    tableWidget->setSortingEnabled(false);
511
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
536
    tableWidget->setRowCount( 1+ tableWidget->rowCount());
512
    tableWidget->setItem(tableWidget->rowCount() - 1, COL_INDEX, new qmTwiNumber(-1));
537
    tableWidget->setItem(tableWidget->rowCount() - 1, COL_INDEX, new qmTwiNumber(-1));
513
}
538
}
514
 
539
 
515
void QmConfClass::cellChanged(int row,int col)
540
void QmConfClass::cellChanged(int row,int col)