Improvements for text alignment

The requested text alignment is always combined with AlignVCenter, which is
the value used before conditional formatting was implemented and gives
better display result.

When creating a new conditional formatting while applying a format from the
toolbar to a column which does not already have one, the alignment flag
of the format is taken from the current cell. In this way, the default text
alignment for numbers is preserved.

See issue #1976 and PR #2013
This commit is contained in:
mgrojo
2019-09-29 13:54:18 +02:00
parent 63aabb9601
commit 6affb875cf
4 changed files with 25 additions and 4 deletions

View File

@@ -594,14 +594,17 @@ void TableBrowser::modifyColumnFormat(std::unordered_set<int> columns, std::func
changeFunction(*it);
m_browseTableModel->addCondFormat(column, *it);
} else {
// Create a new conditional format based on defaults and then modify it as requested using the passed function.
// Alignment is get from the current column since the default is different from text and numbers.
QFont font = QFont(Settings::getValue("databrowser", "font").toString());
font.setPointSize(Settings::getValue("databrowser", "fontsize").toInt());
Qt::Alignment align = Qt::Alignment(m_browseTableModel->data(currentIndex().sibling(currentIndex().row(), column),
Qt::TextAlignmentRole).toInt());
CondFormat newCondFormat(QString(""), QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()),
QColor(Settings::getValue("databrowser", "reg_bg_colour").toString()),
font,
CondFormat::AlignLeft,
CondFormat::fromCombinedAlignment(align),
m_browseTableModel->encoding());
changeFunction(newCondFormat);
m_browseTableModel->addCondFormat(column, newCondFormat);