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.
This commit is contained in:
mgrojo
2019-09-29 12:33:34 +02:00
parent 7541a82050
commit 63aabb9601
20 changed files with 455 additions and 6 deletions

View File

@@ -18,6 +18,7 @@
#include <QScrollBar>
#include <QShortcut>
#include <QTextCodec>
#include <QColorDialog>
QMap<sqlb::ObjectIdentifier, BrowseDataTableSettings> 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<int>::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 &current, 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<int> columns, std::function<void(CondFormat&)> changeFunction)
{
for (int column : columns) {
std::vector<CondFormat>& 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