From 412c239366789924a9cc07f0407a041195cf6d53 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 21 Sep 2019 12:33:16 +0200 Subject: [PATCH 1/7] More conditional formats: font style The conditional format manager allows now to set the font style: bold, italic and underline. The project format has been updated. This is also the base for setting other font formats without further changing the project schema. New icons form the Silk icon set. See issue #1976 and #1815. --- src/CondFormat.cpp | 5 +++-- src/CondFormat.h | 9 ++++++-- src/CondFormatManager.cpp | 20 +++++++++++++++-- src/CondFormatManager.h | 5 ++++- src/CondFormatManager.ui | 42 ++++++++++++++++++++++++++++++++--- src/MainWindow.cpp | 9 +++++++- src/TableBrowser.cpp | 3 ++- src/icons/icons.qrc | 3 +++ src/icons/text_bold.png | Bin 0 -> 304 bytes src/icons/text_italic.png | Bin 0 -> 223 bytes src/icons/text_underline.png | Bin 0 -> 273 bytes src/sqlitetablemodel.cpp | 33 +++++++++++++++++++++------ src/sqlitetablemodel.h | 8 +++---- 13 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 src/icons/text_bold.png create mode 100644 src/icons/text_italic.png create mode 100644 src/icons/text_underline.png diff --git a/src/CondFormat.cpp b/src/CondFormat.cpp index 1f963576..3093ca78 100644 --- a/src/CondFormat.cpp +++ b/src/CondFormat.cpp @@ -2,10 +2,11 @@ #include "Settings.h" #include "Data.h" -CondFormat::CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QString& encoding) +CondFormat::CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QFont& font, const QString& encoding) : m_filter(filter), m_bgColor(background), - m_fgColor(foreground) + m_fgColor(foreground), + m_font(font) { if (!filter.isEmpty()) m_sqlCondition = filterToSqlCondition(filter, encoding); diff --git a/src/CondFormat.h b/src/CondFormat.h index 20a81346..c5666f6d 100644 --- a/src/CondFormat.h +++ b/src/CondFormat.h @@ -3,13 +3,14 @@ #include #include +#include // Conditional formatting for given format to table cells based on a specified condition. class CondFormat { public: CondFormat() {} - explicit CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QString& encoding = QString()); + explicit CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QFont& font, const QString& encoding = QString()); static QString filterToSqlCondition(const QString& value, const QString& encoding = QString()); @@ -18,13 +19,17 @@ private: QString m_filter; QColor m_bgColor; QColor m_fgColor; + QFont m_font; public: QString sqlCondition() const { return m_sqlCondition; } QString filter() const { return m_filter; } QColor backgroundColor() const { return m_bgColor; } QColor foregroundColor() const { return m_fgColor; } - + bool isBold() const { return m_font.bold(); } + bool isItalic() const { return m_font.italic(); } + bool isUnderline() const { return m_font.underline(); } + QFont font() const { return m_font; } }; #endif // CONDFORMAT_H diff --git a/src/CondFormatManager.cpp b/src/CondFormatManager.cpp index 15bfe346..e7f7572c 100644 --- a/src/CondFormatManager.cpp +++ b/src/CondFormatManager.cpp @@ -17,6 +17,10 @@ CondFormatManager::CondFormatManager(const std::vector& condFormats, { ui->setupUi(this); + // Resize columns to contents, except for the condition + for(int col = ColumnForeground; col < ColumnFilter; ++col) + ui->tableCondFormats->resizeColumnToContents(col); + for(const CondFormat& aCondFormat : condFormats) addItem(aCondFormat); @@ -40,6 +44,7 @@ void CondFormatManager::addNewItem() { CondFormat newCondFormat("", QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), + QFont(Settings::getValue("databrowser", "font").toString()), m_encoding); addItem(newCondFormat); } @@ -47,13 +52,16 @@ void CondFormatManager::addNewItem() void CondFormatManager::addItem(const CondFormat& aCondFormat) { int i = ui->tableCondFormats->topLevelItemCount(); - QTreeWidgetItem *newItem = new QTreeWidgetItem({"", "", aCondFormat.filter()}); + QTreeWidgetItem *newItem = new QTreeWidgetItem({"", "", "", "", "", aCondFormat.filter()}); newItem->setForeground(ColumnForeground, aCondFormat.foregroundColor()); newItem->setBackground(ColumnForeground, aCondFormat.foregroundColor()); newItem->setForeground(ColumnBackground, aCondFormat.backgroundColor()); newItem->setBackground(ColumnBackground, aCondFormat.backgroundColor()); newItem->setToolTip(ColumnBackground, tr("Click to select color")); newItem->setToolTip(ColumnForeground, tr("Click to select color")); + newItem->setCheckState(ColumnBold, aCondFormat.isBold() ? Qt::Checked : Qt::Unchecked); + newItem->setCheckState(ColumnItalic, aCondFormat.isItalic() ? Qt::Checked : Qt::Unchecked); + newItem->setCheckState(ColumnUnderline, aCondFormat.isUnderline() ? Qt::Checked : Qt::Unchecked); ui->tableCondFormats->insertTopLevelItem(i, newItem); ui->tableCondFormats->openPersistentEditor(newItem, ColumnFilter); } @@ -100,12 +108,20 @@ void CondFormatManager::downItem() std::vector CondFormatManager::getCondFormats() { std::vector result; + QFont font = Settings::getValue("databrowser", "font").toString(); + for (int i = 0; i < ui->tableCondFormats->topLevelItemCount(); ++i) { QTreeWidgetItem* item = ui->tableCondFormats->topLevelItem(i); + + font.setBold(item->checkState(ColumnBold) == Qt::Checked); + font.setItalic(item->checkState(ColumnItalic) == Qt::Checked); + font.setUnderline(item->checkState(ColumnUnderline) == Qt::Checked); + result.emplace_back(item->text(ColumnFilter), item->background(ColumnForeground).color(), - item->background(ColumnBackground).color(), m_encoding); + item->background(ColumnBackground).color(), + font, m_encoding); } return result; } diff --git a/src/CondFormatManager.h b/src/CondFormatManager.h index 429c16f4..953531ba 100644 --- a/src/CondFormatManager.h +++ b/src/CondFormatManager.h @@ -27,7 +27,10 @@ private: enum Columns { ColumnForeground = 0, ColumnBackground = 1, - ColumnFilter = 2 + ColumnBold = 2, + ColumnItalic = 3, + ColumnUnderline = 4, + ColumnFilter = 5 }; Ui::CondFormatManager *ui; std::vector m_condFormats; diff --git a/src/CondFormatManager.ui b/src/CondFormatManager.ui index 319dd725..7dc57673 100644 --- a/src/CondFormatManager.ui +++ b/src/CondFormatManager.ui @@ -6,7 +6,7 @@ 0 0 - 578 + 600 463 @@ -150,8 +150,8 @@ false - - 150 + + 25 @@ -163,6 +163,42 @@ Background color + + + + + + Bold + + + + :/icons/text_bold.png:/icons/text_bold.png + + + + + + + + Italic + + + + :/icons/text_italic.png:/icons/text_italic.png + + + + + + + + Underline + + + + :/icons/text_underline.png:/icons/text_underline.png + + Condition diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e397a73f..a2467287 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2246,10 +2246,16 @@ static void loadBrowseDataTableSettings(BrowseDataTableSettings& settings, QXmlS int index = xml.attributes().value("index").toInt(); while(xml.readNext() != QXmlStreamReader::EndElement && xml.name() != "column") { if(xml.name() == "format") { + QFont font; + if (xml.attributes().hasAttribute("font")) + font.fromString(xml.attributes().value("font").toString()); + else + Settings::getValue("databrowser", "font").toString(); + settings.condFormats[index].emplace_back(xml.attributes().value("condition").toString(), QColor(xml.attributes().value("foreground").toString()), QColor(xml.attributes().value("background").toString()), - settings.encoding); + font, settings.encoding); xml.skipCurrentElement(); } } @@ -2587,6 +2593,7 @@ static void saveBrowseDataTableSettings(const BrowseDataTableSettings& object, Q xml.writeAttribute("condition", format.filter()); xml.writeAttribute("background", format.backgroundColor().name()); xml.writeAttribute("foreground", format.foregroundColor().name()); + xml.writeAttribute("font", format.font().toString()); xml.writeEndElement(); } xml.writeEndElement(); diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index 15a4e043..1d5cec7f 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -438,9 +438,10 @@ void TableBrowser::updateFilter(int column, const QString& value) void TableBrowser::addCondFormat(int column, const QString& value) { // Create automatically a new conditional format with the next serial background color according to the theme and the regular foreground - // color in the settings. + // color and font in the settings. CondFormat newCondFormat(value, QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), + QFont(Settings::getValue("databrowser", "font").toString()), m_browseTableModel->encoding()); m_browseTableModel->addCondFormat(column, newCondFormat); browseTableSettings[currentlyBrowsedTableName()].condFormats[column].push_back(newCondFormat); diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc index 86caabe3..1baac7e6 100644 --- a/src/icons/icons.qrc +++ b/src/icons/icons.qrc @@ -84,5 +84,8 @@ clear_cond_formats.png edit_cond_formats.png clear_sorting.png + text_bold.png + text_italic.png + text_underline.png diff --git a/src/icons/text_bold.png b/src/icons/text_bold.png new file mode 100644 index 0000000000000000000000000000000000000000..889ae80e37b6167cc15f2a89e05a183815ec18b2 GIT binary patch literal 304 zcmV-00nh%4P)b^}|6b=Y6y(;Y{!a!g z@UQp#@Aw}>L3(}s|7f5BUjeuKZvQRjV<2U7yvu*H{aAbvQ6K!@3oKzW z-{Qa8d3gae1^)HE{~f^!v<1}u>;4xnKvUpW540I-w9J3a{{r=B3T*2g{_BH1CtaZO zpZ`6V0*V5g1e5i;`_=Z#_e=H*@8|93RG@lX;D!K7TKswwko8{x0000C#5QQ<|d}62BjvZR2H60wE-$B^mK6y(Kw&{<9vg>Q9!g~ne(gm zmj4swoA@7?D86%i^8WzK9JM17E&sp&Z#dpHfz$E-U9ks&4?Z9Gyg!%0k2Q{M-Tz#> z2OnD>vrPZ*#{EHKLq)>Jcx{H|Ovdb&|4aQZWSipI{El%e^Cxx{^9vSw28s;a3IDB= TS1%U=TF&6<>gTe~DWM4fm>N^1 literal 0 HcmV?d00001 diff --git a/src/icons/text_underline.png b/src/icons/text_underline.png new file mode 100644 index 0000000000000000000000000000000000000000..90d0df2868871c6cf1bab25affe0d9f8b3f98eac GIT binary patch literal 273 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-$x?CIhdqH#X?$N2_%BY~9*Y!?2h z{rUe=9fy8l?U(-(m`sFEeV_iPeWNmK)A{6xz&-Zw?GGia|0}^&^gUfcv*1X`gnjmc zo{g-_np*x&^x*npDC+Wt-z8{4+sXs`@BiMP%+Rv-k;3)Ae_+S0!x%EHv-|4^N|MkDje{TP~{@MQ}vm3aX7|tvG V&AV6mZa&bt44$rjF6*2UngI1lb~69~ literal 0 HcmV?d00001 diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 1cf04cdf..e42e45ec 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -274,13 +274,17 @@ QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation, return QString("%1").arg(section + 1); } -QColor SqliteTableModel::getMatchingCondFormatColor(int column, const QString& value, int role) const +QVariant SqliteTableModel::getMatchingCondFormat(int column, const QString& value, int role) const { + if (m_mCondFormats.find(column) == m_mCondFormats.end()) + return QVariant(); + bool isNumber; - value.toFloat(&isNumber); + value.toDouble(&isNumber); QString sql; + // For each conditional format for this column, - // if the condition matches the current data, return the associated colour. + // if the condition matches the current data, return the associated format. for (const CondFormat& eachCondFormat : m_mCondFormats.at(column)) { if (isNumber && !eachCondFormat.sqlCondition().contains("'")) sql = QString("SELECT %1 %2").arg(value, eachCondFormat.sqlCondition()); @@ -290,9 +294,16 @@ QColor SqliteTableModel::getMatchingCondFormatColor(int column, const QString& v // Empty filter means: apply format to any row. // Query the DB for the condition, waiting in case there is a loading in progress. if (eachCondFormat.filter().isEmpty() || m_db.querySingleValueFromDb(sql, false, DBBrowserDB::Wait) == "1") - return role == Qt::ForegroundRole ? eachCondFormat.foregroundColor() : eachCondFormat.backgroundColor(); + switch (role) { + case Qt::ForegroundRole: + return eachCondFormat.foregroundColor(); + case Qt::BackgroundRole: + return eachCondFormat.backgroundColor(); + case Qt::FontRole: + return eachCondFormat.font(); + } } - return QColor(); + return QVariant(); } QVariant SqliteTableModel::data(const QModelIndex &index, int role) const @@ -346,6 +357,14 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const QFont font; if(!row_available || cached_row->at(column).isNull() || nosync_isBinary(index)) font.setItalic(true); + else { + QString value = cached_row->at(column); + // Unlock before querying from DB + lock.unlock(); + QVariant condFormatFont = getMatchingCondFormat(index.column(), value, role); + if (condFormatFont.isValid()) + return condFormatFont; + } return font; } else if(role == Qt::ForegroundRole) { if(!row_available) @@ -358,7 +377,7 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const QString value = cached_row->at(column); // Unlock before querying from DB lock.unlock(); - QColor condFormatColor = getMatchingCondFormatColor(index.column(), value, role); + QVariant condFormatColor = getMatchingCondFormat(index.column(), value, role); if (condFormatColor.isValid()) return condFormatColor; } @@ -375,7 +394,7 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const QString value = cached_row->at(column); // Unlock before querying from DB lock.unlock(); - QColor condFormatColor = getMatchingCondFormatColor(index.column(), value, role); + QVariant condFormatColor = getMatchingCondFormat(index.column(), value, role); if (condFormatColor.isValid()) return condFormatColor; } diff --git a/src/sqlitetablemodel.h b/src/sqlitetablemodel.h index 7850014c..02e84a9b 100644 --- a/src/sqlitetablemodel.h +++ b/src/sqlitetablemodel.h @@ -3,7 +3,7 @@ #include #include -#include + #include #include #include @@ -150,9 +150,9 @@ private: QByteArray encode(const QByteArray& str) const; QByteArray decode(const QByteArray& str) const; - // Return matching conditional format color or invalid color, otherwise. - // Only Qt::ForegroundRole and Qt::BackgroundRole are expected in role (Qt::ItemDataRole) - QColor getMatchingCondFormatColor(int column, const QString& value, int role) const; + // Return matching conditional format color/font or invalid value, otherwise. + // Only format roles are expected in role (Qt::ItemDataRole) + QVariant getMatchingCondFormat(int column, const QString& value, int role) const; DBBrowserDB& m_db; From 1ec502ae9b3ffc0cf27d1898d59bcf5b292b982d Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 21 Sep 2019 18:17:16 +0200 Subject: [PATCH 2/7] Added font and point size selection to conditional formats Added font combo box and spin box for selecting font and font point size of a conditional format. The default for a new conditional format is the corresponding setting. Minor dialog adjustments for better display. See issues #1976 and #1815. --- src/CondFormatManager.cpp | 72 ++++++++++++++++++++++++++------------- src/CondFormatManager.h | 13 ++++--- src/CondFormatManager.ui | 20 +++++++++-- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/CondFormatManager.cpp b/src/CondFormatManager.cpp index e7f7572c..60af847d 100644 --- a/src/CondFormatManager.cpp +++ b/src/CondFormatManager.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include CondFormatManager::CondFormatManager(const std::vector& condFormats, const QString& encoding, QWidget *parent) : QDialog(parent), @@ -17,13 +19,13 @@ CondFormatManager::CondFormatManager(const std::vector& condFormats, { ui->setupUi(this); + for(const CondFormat& aCondFormat : condFormats) + addItem(aCondFormat); + // Resize columns to contents, except for the condition for(int col = ColumnForeground; col < ColumnFilter; ++col) ui->tableCondFormats->resizeColumnToContents(col); - for(const CondFormat& aCondFormat : condFormats) - addItem(aCondFormat); - ui->tableCondFormats->setEditTriggers(QAbstractItemView::AllEditTriggers); connect(ui->buttonAdd, SIGNAL(clicked(bool)), this, SLOT(addNewItem())); @@ -52,16 +54,27 @@ void CondFormatManager::addNewItem() void CondFormatManager::addItem(const CondFormat& aCondFormat) { int i = ui->tableCondFormats->topLevelItemCount(); - QTreeWidgetItem *newItem = new QTreeWidgetItem({"", "", "", "", "", aCondFormat.filter()}); + QTreeWidgetItem *newItem = new QTreeWidgetItem(ui->tableCondFormats); newItem->setForeground(ColumnForeground, aCondFormat.foregroundColor()); newItem->setBackground(ColumnForeground, aCondFormat.foregroundColor()); newItem->setForeground(ColumnBackground, aCondFormat.backgroundColor()); newItem->setBackground(ColumnBackground, aCondFormat.backgroundColor()); newItem->setToolTip(ColumnBackground, tr("Click to select color")); newItem->setToolTip(ColumnForeground, tr("Click to select color")); + + QFontComboBox* fontCombo = new QFontComboBox(ui->tableCondFormats); + fontCombo->setCurrentFont(aCondFormat.font()); + ui->tableCondFormats->setItemWidget(newItem, ColumnFont, fontCombo); + + QSpinBox* sizeBox = new QSpinBox(ui->tableCondFormats); + sizeBox->setMinimum(1); + sizeBox->setValue(aCondFormat.font().pointSize()); + ui->tableCondFormats->setItemWidget(newItem, ColumnSize, sizeBox); + newItem->setCheckState(ColumnBold, aCondFormat.isBold() ? Qt::Checked : Qt::Unchecked); newItem->setCheckState(ColumnItalic, aCondFormat.isItalic() ? Qt::Checked : Qt::Unchecked); newItem->setCheckState(ColumnUnderline, aCondFormat.isUnderline() ? Qt::Checked : Qt::Unchecked); + newItem->setText(ColumnFilter, aCondFormat.filter()); ui->tableCondFormats->insertTopLevelItem(i, newItem); ui->tableCondFormats->openPersistentEditor(newItem, ColumnFilter); } @@ -72,48 +85,61 @@ void CondFormatManager::removeItem() delete item; } -void CondFormatManager::upItem() +void CondFormatManager::moveItem(int offset) { if (!ui->tableCondFormats->currentIndex().isValid()) return; int selectedRow = ui->tableCondFormats->currentIndex().row(); - if(selectedRow == 0) + int newRow = selectedRow + offset; + if(newRow < 0 || newRow >= ui->tableCondFormats->topLevelItemCount()) return; - QTreeWidgetItem* item; + QTreeWidgetItem* item = ui->tableCondFormats->topLevelItem(selectedRow); + + // Rescue widgets, since they will be deleted, and add them later. + QFontComboBox* fontCombo = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnFont)); + QFontComboBox* fontCombo2 = new QFontComboBox(ui->tableCondFormats); + fontCombo2->setCurrentFont(fontCombo->currentFont()); + + QSpinBox* sizeBox = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnSize)); + QSpinBox* sizeBox2 = new QSpinBox(ui->tableCondFormats); + sizeBox2->setValue(sizeBox->value()); + sizeBox2->setMinimum(sizeBox->minimum()); + item = ui->tableCondFormats->takeTopLevelItem(selectedRow); - ui->tableCondFormats->insertTopLevelItem(selectedRow-1, item); + ui->tableCondFormats->insertTopLevelItem(newRow, item); + + // Restore widgets and state + ui->tableCondFormats->setItemWidget(item, ColumnFont, fontCombo2); + ui->tableCondFormats->setItemWidget(item, ColumnSize, sizeBox2); ui->tableCondFormats->openPersistentEditor(item, ColumnFilter); - ui->tableCondFormats->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(selectedRow-1, + ui->tableCondFormats->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(newRow, ui->tableCondFormats->currentIndex().column())); } +void CondFormatManager::upItem() +{ + moveItem(-1); +} + void CondFormatManager::downItem() { - if (!ui->tableCondFormats->currentIndex().isValid()) return; - - int selectedRow = ui->tableCondFormats->currentIndex().row(); - if(selectedRow == ui->tableCondFormats->topLevelItemCount() - 1) - return; - - QTreeWidgetItem* item; - item = ui->tableCondFormats->takeTopLevelItem(selectedRow); - ui->tableCondFormats->insertTopLevelItem(selectedRow+1, item); - ui->tableCondFormats->openPersistentEditor(item, ColumnFilter); - ui->tableCondFormats->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(selectedRow+1, - ui->tableCondFormats->currentIndex().column())); + moveItem(+1); } std::vector CondFormatManager::getCondFormats() { std::vector result; - QFont font = Settings::getValue("databrowser", "font").toString(); for (int i = 0; i < ui->tableCondFormats->topLevelItemCount(); ++i) { QTreeWidgetItem* item = ui->tableCondFormats->topLevelItem(i); + QFontComboBox* fontCombo = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnFont)); + QSpinBox* sizeBox = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnSize)); + QFont font = fontCombo->currentFont(); + font.setPointSize(sizeBox->value()); font.setBold(item->checkState(ColumnBold) == Qt::Checked); font.setItalic(item->checkState(ColumnItalic) == Qt::Checked); font.setUnderline(item->checkState(ColumnUnderline) == Qt::Checked); @@ -140,7 +166,7 @@ void CondFormatManager::itemClicked(QTreeWidgetItem* item, int column) } break; } - case ColumnFilter: + default: // Nothing to do break; } diff --git a/src/CondFormatManager.h b/src/CondFormatManager.h index 953531ba..c39551ab 100644 --- a/src/CondFormatManager.h +++ b/src/CondFormatManager.h @@ -26,11 +26,13 @@ public: private: enum Columns { ColumnForeground = 0, - ColumnBackground = 1, - ColumnBold = 2, - ColumnItalic = 3, - ColumnUnderline = 4, - ColumnFilter = 5 + ColumnBackground, + ColumnFont, + ColumnSize, + ColumnBold, + ColumnItalic, + ColumnUnderline, + ColumnFilter }; Ui::CondFormatManager *ui; std::vector m_condFormats; @@ -41,6 +43,7 @@ private slots: void addNewItem(); void addItem(const CondFormat& aCondFormat); void removeItem(); + void moveItem(int offset); void upItem(); void downItem(); void on_buttonBox_clicked(QAbstractButton* button); diff --git a/src/CondFormatManager.ui b/src/CondFormatManager.ui index 7dc57673..69b6241c 100644 --- a/src/CondFormatManager.ui +++ b/src/CondFormatManager.ui @@ -6,7 +6,7 @@ 0 0 - 600 + 640 463 @@ -17,7 +17,7 @@ - This dialog allows creating and editing conditional formats, where the cell text and background will be colored based on one or more conditions. Conditional formats can be moved up and down, where those at higher rows take precedence over those at lower. + This dialog allows creating and editing conditional formats. Each cell style will be selected by the first accomplished condition for that cell data. Conditional formats can be moved up and down, where those at higher rows take precedence over those at lower. An empty condition applies to all values. true @@ -155,14 +155,30 @@ + Foreground + + Text color + Background + + Background color + + + Font + + + + + Size + + From c27002c3010f7e820911feed492d5154ace602c9 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 21 Sep 2019 23:28:35 +0200 Subject: [PATCH 3/7] Added text alignment to conditional formats Combo box for selecting the desired text alignment for a conditional format. The default alignment in the browser has been adjusted for numbers, which are now aligned to the right as in spreadsheets. Project file format updated. See issues #1976 and #1815. --- src/CondFormat.cpp | 24 ++++++++++++++++++++++-- src/CondFormat.h | 23 ++++++++++++++++++++++- src/CondFormatManager.cpp | 19 ++++++++++++++++++- src/CondFormatManager.h | 3 ++- src/CondFormatManager.ui | 9 +++++++-- src/MainWindow.cpp | 9 ++++++++- src/TableBrowser.cpp | 1 + src/sqlitetablemodel.cpp | 12 ++++++++++++ 8 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/CondFormat.cpp b/src/CondFormat.cpp index 3093ca78..60a364df 100644 --- a/src/CondFormat.cpp +++ b/src/CondFormat.cpp @@ -2,11 +2,17 @@ #include "Settings.h" #include "Data.h" -CondFormat::CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QFont& font, const QString& encoding) +CondFormat::CondFormat(const QString& filter, + const QColor& foreground, + const QColor& background, + const QFont& font, + const Alignment alignment, + const QString& encoding) : m_filter(filter), m_bgColor(background), m_fgColor(foreground), - m_font(font) + m_font(font), + m_align(alignment) { if (!filter.isEmpty()) m_sqlCondition = filterToSqlCondition(filter, encoding); @@ -116,3 +122,17 @@ QString CondFormat::filterToSqlCondition(const QString& value, const QString& en return whereClause; } } + +Qt::AlignmentFlag CondFormat::alignmentFlag() const +{ + switch (m_align) { + case AlignLeft: + return Qt::AlignLeft; + case AlignCenter: + return Qt::AlignCenter; + case AlignRight: + return Qt::AlignRight; + case AlignJustify: + return Qt::AlignJustify; + } +} diff --git a/src/CondFormat.h b/src/CondFormat.h index c5666f6d..8c764b63 100644 --- a/src/CondFormat.h +++ b/src/CondFormat.h @@ -9,8 +9,26 @@ class CondFormat { public: + + enum Alignment { + AlignLeft = 0, + AlignRight, + AlignCenter, + AlignJustify + }; + + // List of alignment texts. Order must be as Alignment definition above. + static QStringList alignmentTexts() { + return {QObject::tr("Left"), QObject::tr("Right"), QObject::tr("Center"), QObject::tr("Justify")}; + }; + CondFormat() {} - explicit CondFormat(const QString& filter, const QColor& foreground, const QColor& background, const QFont& font, const QString& encoding = QString()); + explicit CondFormat(const QString& filter, + const QColor& foreground, + const QColor& background, + const QFont& font, + const Alignment alignment = AlignLeft, + const QString& encoding = QString()); static QString filterToSqlCondition(const QString& value, const QString& encoding = QString()); @@ -20,6 +38,7 @@ private: QColor m_bgColor; QColor m_fgColor; QFont m_font; + Alignment m_align; public: QString sqlCondition() const { return m_sqlCondition; } @@ -30,6 +49,8 @@ public: bool isItalic() const { return m_font.italic(); } bool isUnderline() const { return m_font.underline(); } QFont font() const { return m_font; } + Alignment alignment() const { return m_align; } + Qt::AlignmentFlag alignmentFlag() const; }; #endif // CONDFORMAT_H diff --git a/src/CondFormatManager.cpp b/src/CondFormatManager.cpp index 60af847d..87606950 100644 --- a/src/CondFormatManager.cpp +++ b/src/CondFormatManager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include CondFormatManager::CondFormatManager(const std::vector& condFormats, const QString& encoding, QWidget *parent) : QDialog(parent), @@ -47,6 +48,7 @@ void CondFormatManager::addNewItem() CondFormat newCondFormat("", QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), QFont(Settings::getValue("databrowser", "font").toString()), + CondFormat::AlignLeft, m_encoding); addItem(newCondFormat); } @@ -74,6 +76,12 @@ void CondFormatManager::addItem(const CondFormat& aCondFormat) newItem->setCheckState(ColumnBold, aCondFormat.isBold() ? Qt::Checked : Qt::Unchecked); newItem->setCheckState(ColumnItalic, aCondFormat.isItalic() ? Qt::Checked : Qt::Unchecked); newItem->setCheckState(ColumnUnderline, aCondFormat.isUnderline() ? Qt::Checked : Qt::Unchecked); + + QComboBox* alignCombo = new QComboBox(ui->tableCondFormats); + alignCombo->addItems(CondFormat::alignmentTexts()); + alignCombo->setCurrentIndex(aCondFormat.alignment()); + ui->tableCondFormats->setItemWidget(newItem, ColumnAlignment, alignCombo); + newItem->setText(ColumnFilter, aCondFormat.filter()); ui->tableCondFormats->insertTopLevelItem(i, newItem); ui->tableCondFormats->openPersistentEditor(newItem, ColumnFilter); @@ -107,12 +115,18 @@ void CondFormatManager::moveItem(int offset) sizeBox2->setValue(sizeBox->value()); sizeBox2->setMinimum(sizeBox->minimum()); + QComboBox* alignCombo = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnAlignment)); + QComboBox* alignCombo2 = new QComboBox(ui->tableCondFormats); + alignCombo2->addItems(CondFormat::alignmentTexts()); + alignCombo2->setCurrentIndex(alignCombo->currentIndex()); + item = ui->tableCondFormats->takeTopLevelItem(selectedRow); ui->tableCondFormats->insertTopLevelItem(newRow, item); // Restore widgets and state ui->tableCondFormats->setItemWidget(item, ColumnFont, fontCombo2); ui->tableCondFormats->setItemWidget(item, ColumnSize, sizeBox2); + ui->tableCondFormats->setItemWidget(item, ColumnAlignment, alignCombo2); ui->tableCondFormats->openPersistentEditor(item, ColumnFilter); ui->tableCondFormats->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(newRow, ui->tableCondFormats->currentIndex().column())); @@ -143,11 +157,14 @@ std::vector CondFormatManager::getCondFormats() font.setBold(item->checkState(ColumnBold) == Qt::Checked); font.setItalic(item->checkState(ColumnItalic) == Qt::Checked); font.setUnderline(item->checkState(ColumnUnderline) == Qt::Checked); + QComboBox* alignCombo = qobject_cast(ui->tableCondFormats->itemWidget(item, ColumnAlignment)); result.emplace_back(item->text(ColumnFilter), item->background(ColumnForeground).color(), item->background(ColumnBackground).color(), - font, m_encoding); + font, + static_cast(alignCombo->currentIndex()), + m_encoding); } return result; } diff --git a/src/CondFormatManager.h b/src/CondFormatManager.h index c39551ab..344d2e9c 100644 --- a/src/CondFormatManager.h +++ b/src/CondFormatManager.h @@ -32,13 +32,14 @@ private: ColumnBold, ColumnItalic, ColumnUnderline, + ColumnAlignment, ColumnFilter }; Ui::CondFormatManager *ui; std::vector m_condFormats; Palette m_condFormatPalette; QString m_encoding; - + private slots: void addNewItem(); void addItem(const CondFormat& aCondFormat); diff --git a/src/CondFormatManager.ui b/src/CondFormatManager.ui index 69b6241c..e36c0297 100644 --- a/src/CondFormatManager.ui +++ b/src/CondFormatManager.ui @@ -6,8 +6,8 @@ 0 0 - 640 - 463 + 700 + 400 @@ -215,6 +215,11 @@ :/icons/text_underline.png:/icons/text_underline.png + + + Alignment + + Condition diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a2467287..3f39987e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2252,10 +2252,16 @@ static void loadBrowseDataTableSettings(BrowseDataTableSettings& settings, QXmlS else Settings::getValue("databrowser", "font").toString(); + CondFormat::Alignment align; + if (xml.attributes().hasAttribute("align")) + align = static_cast(xml.attributes().value("align").toInt()); + else + align = CondFormat::AlignLeft; + settings.condFormats[index].emplace_back(xml.attributes().value("condition").toString(), QColor(xml.attributes().value("foreground").toString()), QColor(xml.attributes().value("background").toString()), - font, settings.encoding); + font, align, settings.encoding); xml.skipCurrentElement(); } } @@ -2594,6 +2600,7 @@ static void saveBrowseDataTableSettings(const BrowseDataTableSettings& object, Q xml.writeAttribute("background", format.backgroundColor().name()); xml.writeAttribute("foreground", format.foregroundColor().name()); xml.writeAttribute("font", format.font().toString()); + xml.writeAttribute("align", QString().setNum(format.alignment())); xml.writeEndElement(); } xml.writeEndElement(); diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index 1d5cec7f..bab04598 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -442,6 +442,7 @@ void TableBrowser::addCondFormat(int column, const QString& value) CondFormat newCondFormat(value, QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), QFont(Settings::getValue("databrowser", "font").toString()), + CondFormat::AlignLeft, m_browseTableModel->encoding()); m_browseTableModel->addCondFormat(column, newCondFormat); browseTableSettings[currentlyBrowsedTableName()].condFormats[column].push_back(newCondFormat); diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index e42e45ec..53fab3b8 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -301,6 +301,8 @@ QVariant SqliteTableModel::getMatchingCondFormat(int column, const QString& valu return eachCondFormat.backgroundColor(); case Qt::FontRole: return eachCondFormat.font(); + case Qt::TextAlignmentRole: + return eachCondFormat.alignmentFlag(); } } return QVariant(); @@ -409,8 +411,18 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const .arg(QKeySequence(Qt::CTRL).toString(QKeySequence::NativeText)); else return QString(); + } else if (role == Qt::TextAlignmentRole) { + QString value = cached_row->at(column); + lock.unlock(); + QVariant condFormat = getMatchingCondFormat(index.column(), value, role); + if (condFormat.isValid()) + return condFormat; + bool isNumber; + value.toDouble(&isNumber); + return isNumber ? Qt::AlignRight : Qt::AlignLeft; } + return QVariant(); } From 5b73cd1481ed923fb04ca286a4937ca0dc3c255c Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 21 Sep 2019 23:30:28 +0200 Subject: [PATCH 4/7] Fixes when adding new conditional format Font point size preference is taken into account when creating a new default conditional format. New conditional formats in dialog are resized to contents. See issues #1976 and #1815. --- src/CondFormatManager.cpp | 9 ++++++++- src/TableBrowser.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/CondFormatManager.cpp b/src/CondFormatManager.cpp index 87606950..88c298e9 100644 --- a/src/CondFormatManager.cpp +++ b/src/CondFormatManager.cpp @@ -45,12 +45,19 @@ CondFormatManager::~CondFormatManager() void CondFormatManager::addNewItem() { + QFont font = QFont(Settings::getValue("databrowser", "font").toString()); + font.setPointSize(Settings::getValue("databrowser", "fontsize").toInt()); + CondFormat newCondFormat("", QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), - QFont(Settings::getValue("databrowser", "font").toString()), + font, CondFormat::AlignLeft, m_encoding); addItem(newCondFormat); + + // Resize columns to contents, except for the condition + for(int col = ColumnForeground; col < ColumnFilter; ++col) + ui->tableCondFormats->resizeColumnToContents(col); } void CondFormatManager::addItem(const CondFormat& aCondFormat) diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index bab04598..e04946bb 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -437,11 +437,14 @@ void TableBrowser::updateFilter(int column, const QString& value) void TableBrowser::addCondFormat(int column, const QString& value) { + QFont font = QFont(Settings::getValue("databrowser", "font").toString()); + font.setPointSize(Settings::getValue("databrowser", "fontsize").toInt()); + // Create automatically a new conditional format with the next serial background color according to the theme and the regular foreground // color and font in the settings. CondFormat newCondFormat(value, QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), - QFont(Settings::getValue("databrowser", "font").toString()), + font, CondFormat::AlignLeft, m_browseTableModel->encoding()); m_browseTableModel->addCondFormat(column, newCondFormat); @@ -460,6 +463,8 @@ void TableBrowser::editCondFormats(int column) { CondFormatManager condFormatDialog(browseTableSettings[currentlyBrowsedTableName()].condFormats[column], m_browseTableModel->encoding(), this); + condFormatDialog.setWindowTitle(tr("Conditional formats for \"%1\""). + arg(m_browseTableModel->headerData(column, Qt::Horizontal).toString())); if (condFormatDialog.exec()) { std::vector condFormatVector = condFormatDialog.getCondFormats(); m_browseTableModel->setCondFormats(column, condFormatVector); From 7541a8205024368d9f0bdab311e5c6de6e3f8aac Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 22 Sep 2019 23:16:04 +0200 Subject: [PATCH 5/7] Highlight column headers to emulate spreadsheet behaviour The column headers contained in a selection are highlighted for consistency to the row headers and to emulated spreadsheet behaviour. --- src/FilterTableHeader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/FilterTableHeader.cpp b/src/FilterTableHeader.cpp index cd6894b3..c95f40b4 100644 --- a/src/FilterTableHeader.cpp +++ b/src/FilterTableHeader.cpp @@ -17,6 +17,9 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) : // Make sure to not automatically resize the columns according to the contents setSectionResizeMode(QHeaderView::Interactive); + // Highlight column headers of selected cells to emulate spreadsheet behaviour + setHighlightSections(true); + // Do some connects: Basically just resize and reposition the input widgets whenever anything changes connect(this, &FilterTableHeader::sectionResized, this, &FilterTableHeader::adjustPositions); connect(parent->horizontalScrollBar(), &QScrollBar::valueChanged, this, &FilterTableHeader::adjustPositions); From 63aabb9601c6c2d7e5e7e542e02f28013340a8a0 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 29 Sep 2019 12:33:34 +0200 Subject: [PATCH 6/7] Added toolbar for direct formatting of columns in Data Browser The new toolbar is hidden by default and can be toggled using a button in the main Data Browser toolbar. Margins and spacing have been updated to improve appearance of the two toolbars. These tool buttons apply the format to the columns which are contained in the selection. This is done by updating or adding a new condition-less format to the list of conditional formats of those columns. New style icons from the Silk icon set. Changed existent ones for coherence. See issue #1976. --- src/CondFormat.h | 12 ++ src/ExtendedTableWidget.h | 2 + src/FilterLineEdit.cpp | 2 +- src/MainWindow.ui | 15 ++ src/TableBrowser.cpp | 138 ++++++++++++++++ src/TableBrowser.h | 4 + src/TableBrowser.ui | 263 ++++++++++++++++++++++++++++++- src/icons/clear_cond_formats.png | Bin 445 -> 0 bytes src/icons/icons.qrc | 15 +- src/icons/page_paintbrush.png | Bin 0 -> 813 bytes src/icons/style.png | Bin 0 -> 813 bytes src/icons/style_add.png | Bin 0 -> 844 bytes src/icons/style_delete.png | Bin 0 -> 865 bytes src/icons/style_edit.png | Bin 0 -> 927 bytes src/icons/text_align_center.png | Bin 0 -> 234 bytes src/icons/text_align_justify.png | Bin 0 -> 209 bytes src/icons/text_align_left.png | Bin 0 -> 209 bytes src/icons/text_align_right.png | Bin 0 -> 209 bytes src/icons/text_paintbrush.png | Bin 0 -> 880 bytes src/sqlitetablemodel.cpp | 10 +- 20 files changed, 455 insertions(+), 6 deletions(-) delete mode 100644 src/icons/clear_cond_formats.png create mode 100644 src/icons/page_paintbrush.png create mode 100644 src/icons/style.png create mode 100644 src/icons/style_add.png create mode 100644 src/icons/style_delete.png create mode 100644 src/icons/style_edit.png create mode 100644 src/icons/text_align_center.png create mode 100644 src/icons/text_align_justify.png create mode 100644 src/icons/text_align_left.png create mode 100644 src/icons/text_align_right.png create mode 100644 src/icons/text_paintbrush.png diff --git a/src/CondFormat.h b/src/CondFormat.h index 8c764b63..bbef47d8 100644 --- a/src/CondFormat.h +++ b/src/CondFormat.h @@ -43,13 +43,25 @@ private: public: QString sqlCondition() const { return m_sqlCondition; } QString filter() const { return m_filter; } + QColor backgroundColor() const { return m_bgColor; } QColor foregroundColor() const { return m_fgColor; } + void setBackgroundColor(QColor color) { m_bgColor = color; } + void setForegroundColor(QColor color) { m_fgColor = color; } + bool isBold() const { return m_font.bold(); } bool isItalic() const { return m_font.italic(); } bool isUnderline() const { return m_font.underline(); } + void setBold(bool value) { m_font.setBold(value); } + void setItalic(bool value) { m_font.setItalic(value); } + void setUnderline(bool value) { m_font.setUnderline(value); } + QFont font() const { return m_font; } + void setFontFamily(const QString &family) { m_font.setFamily(family); } + void setFontPointSize(int pointSize) { m_font.setPointSize(pointSize); } + Alignment alignment() const { return m_align; } + void setAlignment(Alignment value) { m_align = value; } Qt::AlignmentFlag alignmentFlag() const; }; diff --git a/src/ExtendedTableWidget.h b/src/ExtendedTableWidget.h index 86d650f7..b7b0f7ba 100644 --- a/src/ExtendedTableWidget.h +++ b/src/ExtendedTableWidget.h @@ -70,6 +70,8 @@ signals: void openFileFromDropEvent(QString); void selectedRowsToBeDeleted(); void editCondFormats(int column); + // Make the inherited protected signal public + void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); private: void copyMimeData(const QModelIndexList& fromIndices, QMimeData* mimeData, const bool withHeaders, const bool inSQL); diff --git a/src/FilterLineEdit.cpp b/src/FilterLineEdit.cpp index 39008437..c2717182 100644 --- a/src/FilterLineEdit.cpp +++ b/src/FilterLineEdit.cpp @@ -184,7 +184,7 @@ void FilterLineEdit::showContextMenu(const QPoint &pos) emit clearAllCondFormats(); }); } else { - conditionalFormatAction = new QAction(QIcon(":/icons/cond_formats"), tr("Use for Conditional Format"), editContextMenu); + conditionalFormatAction = new QAction(QIcon(":/icons/add_cond_format"), tr("Use for Conditional Format"), editContextMenu); connect(conditionalFormatAction, &QAction::triggered, [&]() { emit addFilterAsCondFormat(text()); }); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 360d0f29..b0689085 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -124,6 +124,21 @@ You can drag SQL statements from an object row and drop them into other applicat Browse Data + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index e04946bb..8511ff2a 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -18,6 +18,7 @@ #include #include #include +#include QMap TableBrowser::browseTableSettings; QString TableBrowser::defaultBrowseTableEncoding; @@ -127,6 +128,114 @@ TableBrowser::TableBrowser(QWidget* parent) : connect(ui->dataTable->verticalHeader(), &QHeaderView::customContextMenuRequested, this, &TableBrowser::showRecordPopupMenu); connect(ui->dataTable, &ExtendedTableWidget::openFileFromDropEvent, this, &TableBrowser::requestFileOpen); connect(ui->dataTable, &ExtendedTableWidget::selectedRowsToBeDeleted, this, &TableBrowser::deleteRecord); + + connect(ui->fontComboBox, &QFontComboBox::currentFontChanged, this, [this](const QFont &font) { + modifyColumnFormat(ui->dataTable->selectedCols(), [font](CondFormat& format) { format.setFontFamily(font.family()); }); + }); + connect(ui->fontSizeBox, QOverload::of(&QSpinBox::valueChanged), this, [this](int pointSize) { + modifyColumnFormat(ui->dataTable->selectedCols(), [pointSize](CondFormat& format) { format.setFontPointSize(pointSize); }); + }); + + connect(ui->actionFontColor, &QAction::triggered, this, [this]() { + QColor color = QColorDialog::getColor(QColor(m_browseTableModel->data(currentIndex(), Qt::ForegroundRole).toString())); + if(color.isValid()) + modifyColumnFormat(ui->dataTable->selectedCols(), [color](CondFormat& format) { format.setForegroundColor(color); }); + }); + connect(ui->actionBackgroundColor, &QAction::triggered, this, [this]() { + QColor color = QColorDialog::getColor(QColor(m_browseTableModel->data(currentIndex(), Qt::BackgroundRole).toString())); + if(color.isValid()) + modifyColumnFormat(ui->dataTable->selectedCols(), [color](CondFormat& format) { format.setBackgroundColor(color); }); + }); + + connect(ui->actionBold, &QAction::toggled, this, [this](bool checked) { + modifyColumnFormat(ui->dataTable->selectedCols(), [checked](CondFormat& format) { format.setBold(checked); }); + }); + connect(ui->actionItalic, &QAction::toggled, this, [this](bool checked) { + modifyColumnFormat(ui->dataTable->selectedCols(), [checked](CondFormat& format) { format.setItalic(checked); }); + }); + connect(ui->actionUnderline, &QAction::toggled, this, [this](bool checked) { + modifyColumnFormat(ui->dataTable->selectedCols(), [checked](CondFormat& format) { format.setUnderline(checked); }); + }); + + connect(ui->actionLeftAlign, &QAction::triggered, this, [this]() { + ui->actionLeftAlign->setChecked(true); + ui->actionRightAlign->setChecked(false); + ui->actionCenter->setChecked(false); + ui->actionJustify->setChecked(false); + modifyColumnFormat(ui->dataTable->selectedCols(), [](CondFormat& format) { format.setAlignment(CondFormat::AlignLeft); }); + }); + connect(ui->actionRightAlign, &QAction::triggered, this, [this]() { + ui->actionLeftAlign->setChecked(false); + ui->actionRightAlign->setChecked(true); + ui->actionCenter->setChecked(false); + ui->actionJustify->setChecked(false); + modifyColumnFormat(ui->dataTable->selectedCols(), [](CondFormat& format) { format.setAlignment(CondFormat::AlignRight); }); + }); + connect(ui->actionCenter, &QAction::triggered, this, [this]() { + ui->actionLeftAlign->setChecked(false); + ui->actionRightAlign->setChecked(false); + ui->actionCenter->setChecked(true); + ui->actionJustify->setChecked(false); + modifyColumnFormat(ui->dataTable->selectedCols(), [](CondFormat& format) { format.setAlignment(CondFormat::AlignCenter); }); + }); + connect(ui->actionJustify, &QAction::triggered, this, [this]() { + ui->actionLeftAlign->setChecked(false); + ui->actionRightAlign->setChecked(false); + ui->actionCenter->setChecked(false); + ui->actionJustify->setChecked(true); + modifyColumnFormat(ui->dataTable->selectedCols(), [](CondFormat& format) { format.setAlignment(CondFormat::AlignJustify); }); + }); + + connect(ui->actionEditCondFormats, &QAction::triggered, this, [this]() { editCondFormats(currentIndex().column()); }); + connect(ui->actionClearFormat, &QAction::triggered, this, [this]() { + for (int column : ui->dataTable->selectedCols()) + clearAllCondFormats(column); + }); + + connect(ui->dataTable, &ExtendedTableWidget::currentChanged, this, [this](const QModelIndex ¤t, const QModelIndex &) { + // Get cell current format for updating the format toolbar values. Block signals, so the format change is not reapplied. + QFont font = QFont(m_browseTableModel->data(current, Qt::FontRole).toString()); + ui->fontComboBox->blockSignals(true); + ui->fontComboBox->setCurrentFont(font); + ui->fontComboBox->blockSignals(false); + + ui->fontSizeBox->blockSignals(true); + ui->fontSizeBox->setValue(font.pointSize()); + ui->fontSizeBox->blockSignals(false); + + ui->actionBold->blockSignals(true); + ui->actionBold->setChecked(font.bold()); + ui->actionBold->blockSignals(false); + + ui->actionItalic->blockSignals(true); + ui->actionItalic->setChecked(font.italic()); + ui->actionItalic->blockSignals(false); + + ui->actionUnderline->blockSignals(true); + ui->actionUnderline->setChecked(font.underline()); + ui->actionUnderline->blockSignals(false); + + Qt::Alignment align = Qt::Alignment(m_browseTableModel->data(current, Qt::TextAlignmentRole).toInt()); + ui->actionLeftAlign->blockSignals(true); + ui->actionLeftAlign->setChecked(align.testFlag(Qt::AlignLeft)); + ui->actionLeftAlign->blockSignals(false); + + ui->actionRightAlign->blockSignals(true); + ui->actionRightAlign->setChecked(align.testFlag(Qt::AlignRight)); + ui->actionRightAlign->blockSignals(false); + + ui->actionCenter->blockSignals(true); + ui->actionCenter->setChecked(align.testFlag(Qt::AlignCenter)); + ui->actionCenter->blockSignals(false); + + ui->actionJustify->blockSignals(true); + ui->actionJustify->setChecked(align.testFlag(Qt::AlignJustify)); + ui->actionJustify->blockSignals(false); + }); + + connect(ui->actionToggleFormatToolbar, &QAction::toggled, ui->formatFrame, &QFrame::setVisible); + ui->actionToggleFormatToolbar->setChecked(false); + ui->formatFrame->setVisible(false); } TableBrowser::~TableBrowser() @@ -473,6 +582,35 @@ void TableBrowser::editCondFormats(int column) } } +void TableBrowser::modifyColumnFormat(std::unordered_set columns, std::function changeFunction) +{ + for (int column : columns) { + std::vector& columnFormats = browseTableSettings[currentlyBrowsedTableName()].condFormats[column]; + + auto it = std::find_if(columnFormats.begin(), columnFormats.end(), [](const CondFormat& format) { + return format.sqlCondition().isEmpty(); + }); + if(it != columnFormats.end()) { + changeFunction(*it); + m_browseTableModel->addCondFormat(column, *it); + } else { + + QFont font = QFont(Settings::getValue("databrowser", "font").toString()); + font.setPointSize(Settings::getValue("databrowser", "fontsize").toInt()); + + CondFormat newCondFormat(QString(""), QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), + QColor(Settings::getValue("databrowser", "reg_bg_colour").toString()), + font, + CondFormat::AlignLeft, + m_browseTableModel->encoding()); + changeFunction(newCondFormat); + m_browseTableModel->addCondFormat(column, newCondFormat); + browseTableSettings[currentlyBrowsedTableName()].condFormats[column].push_back(newCondFormat); + } + } + emit projectModified(); +} + void TableBrowser::updateRecordsetLabel() { // Get all the numbers, i.e. the number of the first row and the last row as well as the total number of rows diff --git a/src/TableBrowser.h b/src/TableBrowser.h index 3feafa99..fd1594cd 100644 --- a/src/TableBrowser.h +++ b/src/TableBrowser.h @@ -9,6 +9,8 @@ #include #include +#include + class DBBrowserDB; class ExtendedTableWidget; class SqliteTableModel; @@ -169,6 +171,8 @@ private: static QString defaultBrowseTableEncoding; Palette m_condFormatPalette; + + void modifyColumnFormat(std::unordered_set columns, std::function changeFunction); }; #endif diff --git a/src/TableBrowser.ui b/src/TableBrowser.ui index 868e7f5c..7b73be4b 100644 --- a/src/TableBrowser.ui +++ b/src/TableBrowser.ui @@ -6,7 +6,7 @@ 0 0 - 552 + 651 362 @@ -14,6 +14,9 @@ Browse Data + + 1 + 0 @@ -28,6 +31,12 @@ + + 2 + + + 2 + @@ -74,6 +83,8 @@ + + @@ -97,6 +108,64 @@ + + + + + 5 + + + 2 + + + 0 + + + 2 + + + 0 + + + + + + + + + 50 + 16777215 + + + + 1 + + + + + + + Qt::ToolButtonIconOnly + + + + + + + + + + + + + + + + + + + + @@ -127,6 +196,18 @@ + + 2 + + + 2 + + + 2 + + + 2 + @@ -507,6 +588,186 @@ Qt::WidgetShortcut + + + true + + + + :/icons/text_bold.png:/icons/text_bold.png + + + Bold + + + Bold + + + Ctrl+B + + + + + true + + + + :/icons/text_italic.png:/icons/text_italic.png + + + Italic + + + Italic + + + + + true + + + + :/icons/text_underline.png:/icons/text_underline.png + + + Underline + + + Underline + + + Ctrl+U + + + + + true + + + + :/icons/text_align_right.png:/icons/text_align_right.png + + + Align Right + + + Align Right + + + + + true + + + + :/icons/text_align_left.png:/icons/text_align_left.png + + + Align Left + + + Align Left + + + + + true + + + + :/icons/text_align_center.png:/icons/text_align_center.png + + + Center Horizontally + + + Center Horizontally + + + + + true + + + + :/icons/text_align_justify.png:/icons/text_align_justify.png + + + Justify + + + Justify + + + + + + :/icons/edit_cond_formats:/icons/edit_cond_formats + + + Edit Conditional Formats... + + + Edit Conditional Formats... + + + + + + :/icons/clear_cond_formats:/icons/clear_cond_formats + + + Clear Format + + + Clear All Conditional Formats + + + + + + :/icons/foreground_color:/icons/foreground_color + + + Font Color + + + Font Color + + + + + + :/icons/background_color:/icons/background_color + + + Background Color + + + Background Color + + + + + true + + + + :/icons/cond_formats:/icons/cond_formats + + + Toggle Format Toolbar + + + Show/hide format toolbar + + + This button shows or hides the formatting toolbar of the Data Browser + + + This button shows or hides the formatting toolbar of the Data Browser + + diff --git a/src/icons/clear_cond_formats.png b/src/icons/clear_cond_formats.png deleted file mode 100644 index 1646b12c5974e34e012a94d7a8fb11ff4e64cfa9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 445 zcmV;u0Yd(XP)XBBR{{&Wx(21g_0%Xwv_n$(;^+1M4e8NOfI#c=KL?!WJETrYIp^LsMf1(DSo z;U+C_^=G^_=iYw?1_p+oKbRPdoI)8m?jB%ZIMl+x#V^31ATQ7S?&kkO1_p-71ikS8 z^AiRR2}K45uOfuM8zdQ+|1l~M7Y00H4BswnW#HbF#qjg{3x;nD3=E$?F*E#SW_U(a z7#xX^ZeZi(u9g-4!@|P!gyHk+KMW6EGXMSkpage_foreign_key.png save_all.png page_white_text.png - color_swatch.png - clear_cond_formats.png - edit_cond_formats.png + color_swatch.png + edit_cond_formats.png clear_sorting.png text_bold.png text_italic.png text_underline.png + text_align_center.png + text_align_justify.png + text_align_left.png + text_align_right.png + page_paintbrush.png + text_paintbrush.png + style.png + style_edit.png + style_delete.png + style_add.png diff --git a/src/icons/page_paintbrush.png b/src/icons/page_paintbrush.png new file mode 100644 index 0000000000000000000000000000000000000000..246a2f0b426faa0c7f5ba009e32b1deaf88d1288 GIT binary patch literal 813 zcmV+|1JeA7P)otxGRZMDZ!_a~nK|b_-`n%VosaL{KDuPV10`(1LIen8kX2Xff$3BE zah#djvFGJ&eE^89Pk*-O^+&d>FC~^GjRYVQ(uuPJyS|-v?9lxA-+tM5>1Qu*n+Ir1 z6KhA>X4$XDH6?-|E5oe1E?pQ5-M;2xw_ex!x}I2+b=}mPFW$U%^;o(Zg*LP!K^1kP%8ynsD^= z1y^6xD1#GLjO{VLdh@0GKY7;d$+NGukV)GRLPn^=q=dF%B#XaJrNP`0E6=}e&Gj3d zKJbQre*WXt!60_DnIzgMQc6S#fvjXxsE1v7;T;njHkdy2miIqAS(nX~o%cO+q+b#h z5tIleLWvL=dQE8OC#{%y*Tnku&K`Tuub&_ELI0t_ea{@3f>Jv&sYqld(%}3_GY3Dm z;O{3*Y?v^A`a|D;^qrM=ykI)U6QHd%WhO~VF!SGjGn0GOZrc3mGZudNl9{Q#X5&-F zuGwVReFLBjE5jr!!^-5*L%!I%PkYH#Hs5rMrEBl^)9)9XTD;xjHFxVZMc3~Dw6#k$ z(-S}RE$bgMHv6Z`mS5|u$$78sp4G-8b@lVkl`HtEv+MGn!F&bKcHPi$$oP_;=BrPf z$(~b3&p3CsuQxhoV$%jIR;`lB-s7FDX)xCTXuJ7ZyIQk96uIR=HBt%-P?N*bp`)EF zq14c}QM+O70NTOa@V~_)&GMZ$^cQDlkyOCa(H3Mf+6xhCuZh`VSN{cQBl5Ys9{cp( rh`2H3A^=GuC6HjQ*7|*0>;m{7QlnX3z3MSD00000NkvXXu0mjfR5FYo literal 0 HcmV?d00001 diff --git a/src/icons/style.png b/src/icons/style.png new file mode 100644 index 0000000000000000000000000000000000000000..81e41de7d3a9bcc50267b34d0005487d5c7cc7c0 GIT binary patch literal 813 zcmV+|1JeA7P)%S8Yz4}?d^ZEOv#Sc!)mtIgHXaEQ+_ullV zJO1Y8v8UhuAAS7ozvIlitK{;}YszGvVI*jPQs)gu{RuZGF1qsJqxF>Ai*mOY zeUVJ^Xn04=g+vNN2-6q_7DHe6!8fa@! z^ZEB_2Vebf-umoI@{HTtK!PIfdyIp7Zk$|p=*|D=N%#IIE_w1_EaGe}ST5wWclgx% z|Fx4ZY{8likTKA?G12oM|4&}@o+);3yYs=L?ao)At-(S*$63Le zJ&q^>ZEbL?y!O>L=h9<7rvvdA2Do?L{p8zs_rGt?o&P=^cm5ltT|5S~l@laqmU8i; rSIv!oK>XjU`o@3v@@qdCD9z3Q7_5=EFk?|V00000NkvXXu0mjffa;^e literal 0 HcmV?d00001 diff --git a/src/icons/style_add.png b/src/icons/style_add.png new file mode 100644 index 0000000000000000000000000000000000000000..e0369c6be9d36e994b0de011069494460d96a837 GIT binary patch literal 844 zcmV-S1GD^zP)e0@+Julu(JNEkTghQ`>*6)1&K56lT)AFSk6p+=zFou9~?@f=o z<8N*rd;0DF(Z}EZJI=hjN-qDrrcCA;MuG+?b>3jqpKx>HqAMRhT2HyXD0l0#iaLPj_0@CCfwX2oqfq#v-#E>^WJ+0O*-%H zHfg=H+pP80LCw-@%MhBYE~}R8d~tQ=>345r($1Jk$Dh=ha`5$Q|0%Z*NM~MfR<5`? z*=OG4&)FMa{LftT;=fMmjdkL&7s}uU7`0rTx%v91Kl4t$`!M0as~0m4zJ7b)=BNL$ zv+kY|^Ex1>-*9Vvz`RHQoOC>ZM%CJXsdg~+{gcAqR#h%!vGjSdf96p zUz&8_)hmghBZe>+iF)o;PnvP(V#cg{58Ni-fA2Qo-b=Bl^VUFHgCb`>{I8mLVHwzf zj-AiHPdoVPfAiL7Uy^6s-UbpBao=Mc+;ijPvO{nFM^C!rXeXPW->+%GCcCp6&YIzdP%Hc)#v{<8+;QI1SLuzO*J`-lP9w z!6%zz+g-kIygcFm#%q)QgFw%o)c^f^(*K)hOZ~vm2n-}+(aVjYFP!CqB_qTX zOJ&0en^&%FY~D`yo5wuXrqeuThwbe*!4lN!gNF~E?|Yv2;o&s_0FxcK)F4Mv>u0z* zJhiT>SNoIRsri=6U06{-CYN%OHJ$srT8APibiLY-K*7FMO` zu!-u4!CmVjT89blRPxkIDKC*hn?y-keBB&eC_)C&se#e8D!|7|Y1Eu$<>Pfv>N49K>6fy0A2YR8!Poer$)vwrolN$#@;q4<}Pej2{e%3 zI=@b?o@g_YM+14D#L_V#yK@oZ%9M~)Hw)Nk$>Z&}>!Pcq%1JmymbL7=2fKmBjgNb+ z0y1kBXpaiveUuCEe9fUL91qlp8>1G%-IfQ7F?q0R5`%pM_H zlBZRaI3ut~u@Y3I*su)iBl3JP27{y#cAw>392ogM27x8WYUncrLQ548Qmg=v)c#(M zKW28lmJEQ3zM`w6LouCZ2JeDx41XWS7nLH=8uZMsJl-Y~+6d*|L+TPovcw00000NkvXXu0mjf$UutB literal 0 HcmV?d00001 diff --git a/src/icons/style_edit.png b/src/icons/style_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..25bb5b677f89b1071fa44f29a006ed0be8fca098 GIT binary patch literal 927 zcmV;Q17Q4#P)4 za;GYM@Zfsyfm)fD&Ry41qf>=r$+ULd=aUgoB$PD=lkdf_7Ilg?zyQOl7->rK6-vac z;TV_Zv*2yTAsc({lxwkakt#&M=^sjC#7^AUP&&Nl19N&`|TDi=7JD}Yd0Ws1C z>4Cn`%K-NAO-Gb$R zVwgTXc$E4*bT1D$0aYNf*Tq)K^tV$NSHqh(`FgCPo#PoB*clz&@Zz?t*3^<<*(b1GSS=liGL+!XKb`BrUt80E|` zL^nZdavGLlE*g6AK5q89fuGJSBa^o|%9F?I)(M}uC9Y*LTOPY~cz<|nclXlE}xo*2>>r;3Jd?&=tr_!Iww zFvhUfzU@K1>#kb5wJi!Jl*ja3{?P6ZuOx9B{{rz!RGKb8<;DO2002ovPDHLkV1j*g BxhDVs literal 0 HcmV?d00001 diff --git a/src/icons/text_align_center.png b/src/icons/text_align_center.png new file mode 100644 index 0000000000000000000000000000000000000000..57beb3813973e69f535a822c2f0424fa9f560303 GIT binary patch literal 234 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-%s@pN$v(Kw&{=X`^_fnmU^23D6T z|NkHVz|K?O{7~QE-_Z@zCpI>Iv^P{UFnE&ke;(6i-d4-w%bHR;j1|AyZ#v6S(amDc zlKy{I(;D%Nuye{ncOLwezxwWez>k>{<_3S*oiFG7{Xgq}=)co{r~lFaH2=T-_xf)+ f9X!fMH*zv8ak(u6{1-oD!MC#5QQ<|d}62BjvZR2H60wE-$h_H=O!(Kw&{=X`^_fnmU^23D6T z|NkHVz|K?O{7~QE-_Z@zCpI>Iv^P`}`P2Tg^+n4;W0%&Nn`h_oB zXMCTNA-w1R;@9m5&b!P``2Amf(pd!#&g=F^W;hsZV)z*wDqmKyKNDyjgQu&X%Q~lo FCIDq2QD*=E literal 0 HcmV?d00001 diff --git a/src/icons/text_align_left.png b/src/icons/text_align_left.png new file mode 100644 index 0000000000000000000000000000000000000000..6c8fcc1165a433617355ac5e182d015b389e9296 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-$h_H=O!(Kw&{=X`^_fnmU^23D6T z|NkHVz|K?O{7~QE-_Z@zCpI>Iv^P`}`P2Tg^~Il~8@dITHCPA-{a3!-)3Cjx%=yXx z_>8LclV7mqn+PY^{qor&o%8>H%d3``{~Y#6bGV5yoI2touNPXs5@;QRr>mdKI;Vst E04%Lf&j0`b literal 0 HcmV?d00001 diff --git a/src/icons/text_align_right.png b/src/icons/text_align_right.png new file mode 100644 index 0000000000000000000000000000000000000000..a1502571c99fb92b1579c3658bcc50c5976b8e7d GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-$h_H=O!(Kw&{=X`^_fnmU^23D6T z|NkHVz|K?O{7~QE-_Z@zCpI>Iv^P|9aJcmUe!yIVina{lp#RFZdm6TTlr;aYZ;9)u zJl|<{@VEV{yZaY@Fz(E|@awIMUm8pNTsacVC@HkyaNDlS)vn+`Eo>(J?v0G>&9`S zr%OJ9IPx)LbR3&G#%y@>PP+f#S>GB}q@CZz4%hmI3E2l{Q-v)gLjhw;ni(^P+!PBD zc3t;ZOdS(9CETxsHIW9o&t&S}vcypi*ZO)#T8@37=K`q0Sbn%blWD=eT<7MJE8XS3 zrr>c4$CxZJtW7t@xV&YFqaChw&xN!cyC&X5{heECMCKL`0+RQ>OkF<9Uep_m2EX=( zFKQwcow39kOIY)qgi5EwwXR-BciVWT8l8=Gh{)XTyyBk9!53^MwrF0GDg9%RibboE zZWtMccL_1Jw&pj(wqyrR3F+@Av$Vn&|cU2SPGGi-;IeT(g{m*g09EuM3 z{a*?X&ZJDsM0ZOUx|%*M$S?JIeoi6*01cX>O^!Vlud?pB(^D`h*#Ie&it2m8 zw~d~wf)pZ!zY_xhIaG1p5RPhjs)S{H>LlE*_v3hF6n0}6kzh*GWYIFGptQyRr!J77 z$XsNIDbHYcAT+>2RIQL$GhV%I>>qB>b`%`_vlsx#=P&XyNe)5|cOx8Dp(qr5O#B@y zFP}bBvc2`6+IXX44}l(?0i9+;i=Kc^B|z1etSt}y4e$-7e_J6FGenR80000 SqliteTableModel::getColumns(std::shared_ptr p void SqliteTableModel::addCondFormat(int column, const CondFormat& condFormat) { - m_mCondFormats[column].push_back(condFormat); + // If the condition is already present in the vector, update that entry and respect the order, since two entries with the same + // condition do not make sense. + auto it = std::find_if(m_mCondFormats[column].begin(), m_mCondFormats[column].end(), [condFormat](const CondFormat& format) { + return format.sqlCondition() == condFormat.sqlCondition(); + }); + if(it != m_mCondFormats[column].end()) { + *it = condFormat; + } else + m_mCondFormats[column].push_back(condFormat); emit layoutChanged(); } From 6affb875cf2b88692b4b2780227348db1a9960e1 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 29 Sep 2019 13:54:18 +0200 Subject: [PATCH 7/7] 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 --- src/CondFormat.cpp | 12 ++++++++++++ src/CondFormat.h | 4 ++++ src/TableBrowser.cpp | 7 +++++-- src/sqlitetablemodel.cpp | 6 ++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/CondFormat.cpp b/src/CondFormat.cpp index 60a364df..db3699f5 100644 --- a/src/CondFormat.cpp +++ b/src/CondFormat.cpp @@ -2,6 +2,18 @@ #include "Settings.h" #include "Data.h" +CondFormat::Alignment CondFormat::fromCombinedAlignment(Qt::Alignment align) +{ + if (align.testFlag(Qt::AlignLeft)) + return AlignLeft; + if (align.testFlag(Qt::AlignRight)) + return AlignRight; + if (align.testFlag(Qt::AlignCenter)) + return AlignCenter; + if (align.testFlag(Qt::AlignJustify)) + return AlignJustify; +} + CondFormat::CondFormat(const QString& filter, const QColor& foreground, const QColor& background, diff --git a/src/CondFormat.h b/src/CondFormat.h index bbef47d8..edbafb65 100644 --- a/src/CondFormat.h +++ b/src/CondFormat.h @@ -22,6 +22,10 @@ public: return {QObject::tr("Left"), QObject::tr("Right"), QObject::tr("Center"), QObject::tr("Justify")}; }; + // Get alignment from combined Qt alignment (note that this will lose any combination of our Alignment enum + // with other values present in the flag (e.g. vertical alignment). + static Alignment fromCombinedAlignment(Qt::Alignment align); + CondFormat() {} explicit CondFormat(const QString& filter, const QColor& foreground, diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index 8511ff2a..450a1fb4 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -594,14 +594,17 @@ void TableBrowser::modifyColumnFormat(std::unordered_set 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); diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index f3a032ee..e2d090c6 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -302,7 +302,7 @@ QVariant SqliteTableModel::getMatchingCondFormat(int column, const QString& valu case Qt::FontRole: return eachCondFormat.font(); case Qt::TextAlignmentRole: - return eachCondFormat.alignmentFlag(); + return static_cast(eachCondFormat.alignmentFlag() | Qt::AlignVCenter); } } return QVariant(); @@ -412,6 +412,8 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const else return QString(); } else if (role == Qt::TextAlignmentRole) { + // Align horizontally according to conditional format or default (left for text and right for numbers) + // Align vertically to the center, which displays better. QString value = cached_row->at(column); lock.unlock(); QVariant condFormat = getMatchingCondFormat(index.column(), value, role); @@ -419,7 +421,7 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const return condFormat; bool isNumber; value.toDouble(&isNumber); - return isNumber ? Qt::AlignRight : Qt::AlignLeft; + return static_cast((isNumber ? Qt::AlignRight : Qt::AlignLeft) | Qt::AlignVCenter); }