Add an option to keep the folio row and column headers visible (#1034)

Affichage > "Garder les en-têtes visibles" adds a bar along the top and
the left of the diagram view that repeats the folio's column numbers and
row letters, aligned with the cells at any zoom, so they stay in sight
when the folio's own headers are scrolled away. Off by default; the
choice is stored as diagrameditor/cell_rulers.

The bars are CellRuler widgets in the view's margins
(setViewportMargins), not scene items, so printing and PDF/PNG/DXF
export never see them, and they paint with the application palette
outside of the dark-palette inversion. They keep a constant thickness;
when cells get narrower than their labels, only every 2nd, 5th, 10th...
label is written. A bar is hidden when the folio hides that header.
Showing or hiding them keeps the centre of the view where it was.

The labels come from BorderCellLabels, now also used by
BorderTitleBlock::draw(), so the bars and the border cannot disagree.
PNG export of all 133 folios of the examples is pixel-identical to
master, with border-columns_0 true and false.

Known limits: changing border-columns_0 repaints the bars at the next
scroll or zoom; the menu toggle updates the views of its own editor
window only, like the grid toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-26 08:22:12 +12:00
parent 5f0b015186
commit 9738345b45
11 changed files with 460 additions and 11 deletions
+6
View File
@@ -84,6 +84,12 @@ add_test(NAME tst_diagramsortkeys COMMAND tst_diagramsortkeys)
target_include_directories(tst_diagramsortkeys PRIVATE ${QET_DIR}/sources)
target_link_libraries(tst_diagramsortkeys PRIVATE Qt::Test)
# bordercelllabels.h is header-only too.
add_executable(tst_bordercelllabels tst_bordercelllabels.cpp)
add_test(NAME tst_bordercelllabels COMMAND tst_bordercelllabels)
target_include_directories(tst_bordercelllabels PRIVATE ${QET_DIR}/sources)
target_link_libraries(tst_bordercelllabels PRIVATE Qt::Test)
# contactusage.h is a header-only helper holding the contact counting
# rules, so this test builds independently of the rest of the QET sources.
add_executable(tst_contactusage tst_contactusage.cpp)
+55
View File
@@ -0,0 +1,55 @@
#include <QtTest>
#include "bordercelllabels.h"
class tst_bordercelllabels : public QObject
{
Q_OBJECT
// A copy of BorderTitleBlock::incrementLetters(), the walk the folio
// border used to draw its row labels with, as the reference rowLabel()
// must reproduce.
static QString incrementLetters(const QString &string)
{
if (string.isEmpty())
return QStringLiteral("A");
const QString first_digits(string.left(string.length() - 1));
const QChar last_digit(string.at(string.length() - 1));
if (last_digit != QLatin1Char('Z'))
return first_digits + QChar(last_digit.unicode() + 1);
return incrementLetters(first_digits) + QLatin1Char('A');
}
private slots:
void rowLabelsFollowTheBorderSequence()
{
QString expected(QStringLiteral("A"));
for (int row = 1; row <= 1000; ++row) {
QCOMPARE(BorderCellLabels::rowLabel(row), expected);
expected = incrementLetters(expected);
}
}
void rowLabelSamples()
{
QCOMPARE(BorderCellLabels::rowLabel(1), QStringLiteral("A"));
QCOMPARE(BorderCellLabels::rowLabel(26), QStringLiteral("Z"));
QCOMPARE(BorderCellLabels::rowLabel(27), QStringLiteral("AA"));
QCOMPARE(BorderCellLabels::rowLabel(52), QStringLiteral("AZ"));
QCOMPARE(BorderCellLabels::rowLabel(53), QStringLiteral("BA"));
QCOMPARE(BorderCellLabels::rowLabel(702), QStringLiteral("ZZ"));
QCOMPARE(BorderCellLabels::rowLabel(703), QStringLiteral("AAA"));
}
void columnLabels()
{
QCOMPARE(BorderCellLabels::columnLabel(1, true), QStringLiteral("0"));
QCOMPARE(BorderCellLabels::columnLabel(1, false), QStringLiteral("1"));
QCOMPARE(BorderCellLabels::columnLabel(17, true), QStringLiteral("16"));
QCOMPARE(BorderCellLabels::columnLabel(17, false), QStringLiteral("17"));
}
};
QTEST_APPLESS_MAIN(tst_bordercelllabels)
#include "tst_bordercelllabels.moc"