@@ -70,6 +70,17 @@ bool TableGroupItem::setContainer(QQuickItem* container) noexcept
70
70
if (cell != nullptr )
71
71
cell->setParentItem (container);
72
72
73
+ // Note 20240830: React to size modifications, usually table size
74
+ // is fully initialized at this point, to prevent spurious reaction
75
+ // set setEnabled(false).
76
+ const auto container = getContainer ();
77
+ if (container != nullptr ) {
78
+ connect (container, &QQuickItem::widthChanged,
79
+ this , &TableGroupItem::layoutTable);
80
+ connect (container, &QQuickItem::heightChanged,
81
+ this , &TableGroupItem::layoutTable);
82
+ }
83
+
73
84
return true ;
74
85
}
75
86
return false ;
@@ -298,7 +309,6 @@ auto TableGroupItem::createFromComponent(QQmlComponent& component) -> QQuickItem
298
309
299
310
void TableGroupItem::initializeTableLayout ()
300
311
{
301
- // qWarning() << "qan::TableGroupItem::initializeTableLayout()";
302
312
const auto tableGroup = getTableGroup ();
303
313
if (tableGroup == nullptr )
304
314
return ;
@@ -308,6 +318,7 @@ void TableGroupItem::initializeTableLayout()
308
318
const auto tableWidth = tableContainer->width ();
309
319
const auto tableHeight = tableContainer->height ();
310
320
const auto tableSize = tableContainer->size ();
321
+ qWarning () << " qan::TableGroupItem::initializeTableLayout(): tableSize=" << tableSize;
311
322
if (qRound (tableWidth) <= 0 || qRound (tableHeight) <= 0 )
312
323
return ;
313
324
@@ -358,7 +369,8 @@ void TableGroupItem::initializeTableLayout()
358
369
((c - 1 ) * spacing) +
359
370
(c * cellWidth) +
360
371
(spacing / 2 .);
361
- verticalBorder->setX (x - borderWidth2);
372
+ const auto borderX = x - borderWidth2;
373
+ verticalBorder->setSx (borderX / tableWidth);
362
374
verticalBorder->setY (0 .);
363
375
verticalBorder->setWidth (borderWidth);
364
376
verticalBorder->setHeight (tableHeight);
@@ -377,7 +389,10 @@ void TableGroupItem::initializeTableLayout()
377
389
(r * cellHeight) +
378
390
(spacing / 2 .);
379
391
horizontalBorder->setX (0 .);
380
- horizontalBorder->setY (y - borderHeight2);
392
+ // FIXME #1756 BTW, ce serait peut-être bien aussi de normaliser
393
+ // width et heght en prevision merge...
394
+ const auto borderY = y - borderHeight2;
395
+ horizontalBorder->setSy (borderY / tableHeight);
381
396
horizontalBorder->setWidth (tableWidth);
382
397
horizontalBorder->setHeight (borderHeight);
383
398
}
@@ -388,20 +403,9 @@ void TableGroupItem::initializeTableLayout()
388
403
// it will be called automatically when border are moved.
389
404
// Note 20230406: In fact calling layout cell is necessary for rows==1, cols==1
390
405
// table that need special handling to dimension cells since there is no horiz/vert borders.
391
- layoutCells ();
392
-
393
- _previousSize = tableSize; // Set a correct initial size
394
-
395
- // Note 20240830: React to size modifications, usually table size
396
- // is fully initialized at this point, to prevent spurious reaction
397
- // set setEnabled(false).
398
- const auto container = getContainer ();
399
- if (container != nullptr ) {
400
- connect (container, &QQuickItem::widthChanged,
401
- this , &TableGroupItem::layoutTable);
402
- connect (container, &QQuickItem::heightChanged,
403
- this , &TableGroupItem::layoutTable);
404
- }
406
+ // FIXME #1756
407
+ layoutTable ();
408
+ // layoutCells();
405
409
}
406
410
407
411
void TableGroupItem::layoutTable ()
@@ -420,63 +424,49 @@ void TableGroupItem::layoutTable()
420
424
const auto tableWidth = tableContainer->width ();
421
425
const auto tableHeight = tableContainer->height ();
422
426
423
- if ( qAbs (tableWidth - width ()) > 10 ) // Note 20240904: Table container size must be _almost_ equal to
424
- return ; // table group size otherwise we perhaps are still in a polish loop
425
- if (qAbs (tableHeight - height ()) > 70 )
427
+ // During initial polish loop and since we are binded directly on width/
428
+ // height change, table container size might be empty.
429
+ if (tableSize. isEmpty () || tableSize. isNull () )
426
430
return ;
427
431
428
- // qWarning() << "TableGroupItem::layoutTable(): " << getGroup()->getLabel() <<
429
- // " tableWidth=" << tableWidth << "tableHeight=" << tableHeight <<
430
- // " _previousSize=" << _previousSize;
431
- // qWarning() << " groupSize" << size();
432
- // qWarning() << " _previousSize.isNull()=" << _previousSize.isNull();
433
- // qWarning() << " _previousSize.isValid()=" << _previousSize.isValid();
434
- // qWarning() << " _previousSize.isEmpty()=" << _previousSize.isEmpty();
435
- if (_previousSize.isNull ()) {
436
- if (!tableSize.isEmpty ())
437
- _previousSize = tableSize;
438
- return ;
439
- }
440
- if (_previousSize == tableSize)
441
- return ;
432
+ qWarning () << " TableGroupItem::layoutTable(): " << getGroup ()->getLabel () <<
433
+ " tableWidth=" << tableWidth << " tableHeight=" << tableHeight;
442
434
443
435
for (const auto verticalBorder: _verticalBorders) {
444
436
if (verticalBorder == nullptr )
445
437
continue ;
446
- const auto previousX = verticalBorder->x ();
447
- verticalBorder->setX ((previousX / _previousSize.width ()) * tableWidth);
438
+ // FIXME #1756
439
+ // const auto previousX = verticalBorder->x();
440
+ // verticalBorder->setX((previousX / _previousSize.width()) * tableWidth);
441
+ verticalBorder->setX (verticalBorder->getSx () * tableWidth);
448
442
verticalBorder->setY (0 .);
449
443
verticalBorder->setHeight (tableHeight);
450
444
}
451
445
452
446
for (const auto horizontalBorder: _horizontalBorders) {
453
447
if (horizontalBorder == nullptr )
454
448
continue ;
455
- const auto previousY = horizontalBorder->y ();
456
449
horizontalBorder->setX (0 .);
457
- horizontalBorder->setY ((previousY / _previousSize.height ()) * tableHeight);
450
+ // FIXME #1756
451
+ // const auto previousY = horizontalBorder->y();
452
+ // horizontalBorder->setY((previousY / _previousSize.height()) * tableHeight);
453
+ horizontalBorder->setY (horizontalBorder->getSy () * tableHeight);
458
454
horizontalBorder->setWidth (tableWidth);
459
455
}
460
456
461
- _previousSize = tableSize;
462
457
layoutCells ();
463
458
}
464
459
465
460
void TableGroupItem::polishTable ()
466
461
{
462
+ // FIXME #1756 no longer necessary ????
463
+
467
464
if (!isEnabled ())
468
465
return ; // Note 20240830: prevent spurious layouts during serialization (see hlg::TableGroup::serializeFromJson()).
469
466
const auto tableContainer = getContainer ();
470
467
if (tableContainer == nullptr )
471
468
return ;
472
469
layoutCells ();
473
- const auto container = getContainer ();
474
- if (container != nullptr ) {
475
- connect (container, &QQuickItem::widthChanged,
476
- this , &TableGroupItem::layoutTable);
477
- connect (container, &QQuickItem::heightChanged,
478
- this , &TableGroupItem::layoutTable);
479
- }
480
470
}
481
471
482
472
void TableGroupItem::layoutCells ()
@@ -522,7 +512,6 @@ void TableGroupItem::layoutCells()
522
512
cell->setY (padding);
523
513
}
524
514
}
525
- // _previousSize = tableSize;
526
515
}
527
516
528
517
bool TableGroupItem::setGroup (qan::Group* group) noexcept
0 commit comments