Merge pull request #1038 from ispyisail/feature/cell-rulers

Add an option to keep the folio row and column headers visible (#1034)
This commit is contained in:
Laurent Trinques
2026-09-26 08:43:42 +02:00
committed by GitHub
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"