mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Merge branch 'master' into browser_formats
Necessary changes: - Added function `ExtendedTableWidget::colsInSelection` to emulate former behaviour of `ExtendedTableWidget::selectedCols`, which is needed by the format toolbar. - Added call to `ui->dataTable->scrollTo(match);` in TableBrowser::find, otherwise the scroll was not advancing to the current index. # Conflicts: # src/TableBrowser.cpp # src/TableBrowser.ui # src/icons/icons.qrc # src/sqlitetablemodel.cpp
This commit is contained in:
@@ -130,31 +130,31 @@ TableBrowser::TableBrowser(QWidget* parent) :
|
||||
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()); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [checked](CondFormat& format) { format.setUnderline(checked); });
|
||||
});
|
||||
|
||||
connect(ui->actionLeftAlign, &QAction::triggered, this, [this]() {
|
||||
@@ -162,33 +162,33 @@ TableBrowser::TableBrowser(QWidget* parent) :
|
||||
ui->actionRightAlign->setChecked(false);
|
||||
ui->actionCenter->setChecked(false);
|
||||
ui->actionJustify->setChecked(false);
|
||||
modifyColumnFormat(ui->dataTable->selectedCols(), [](CondFormat& format) { format.setAlignment(CondFormat::AlignLeft); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [](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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [](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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [](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); });
|
||||
modifyColumnFormat(ui->dataTable->colsInSelection(), [](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())
|
||||
for (int column : ui->dataTable->colsInSelection())
|
||||
clearAllCondFormats(column);
|
||||
});
|
||||
|
||||
@@ -236,6 +236,41 @@ TableBrowser::TableBrowser(QWidget* parent) :
|
||||
connect(ui->actionToggleFormatToolbar, &QAction::toggled, ui->formatFrame, &QFrame::setVisible);
|
||||
ui->actionToggleFormatToolbar->setChecked(false);
|
||||
ui->formatFrame->setVisible(false);
|
||||
|
||||
// Set up find frame
|
||||
ui->frameFind->hide();
|
||||
|
||||
QShortcut* shortcutHideFindFrame = new QShortcut(QKeySequence("ESC"), ui->editFindExpression);
|
||||
connect(shortcutHideFindFrame, &QShortcut::activated, ui->buttonFindClose, &QToolButton::click);
|
||||
|
||||
connect(ui->actionFind, &QAction::triggered, [this](bool checked) {
|
||||
if(checked)
|
||||
{
|
||||
ui->frameFind->show();
|
||||
ui->editFindExpression->setFocus();
|
||||
} else {
|
||||
ui->buttonFindClose->click();
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->editFindExpression, &QLineEdit::returnPressed, ui->buttonFindNext, &QToolButton::click);
|
||||
connect(ui->editFindExpression, &QLineEdit::textChanged, this, [this]() {
|
||||
// When the text has changed but neither Return nor F3 or similar nor any buttons were pressed, we want to include the current
|
||||
// cell in the search as well. This makes sure the selected cell does not jump around every time the text is changed but only
|
||||
// when the current cell does not match the search expression anymore.
|
||||
find(ui->editFindExpression->text(), true, true);
|
||||
});
|
||||
connect(ui->buttonFindClose, &QToolButton::clicked, this, [this](){
|
||||
ui->dataTable->setFocus();
|
||||
ui->frameFind->hide();
|
||||
ui->actionFind->setChecked(false);
|
||||
});
|
||||
connect(ui->buttonFindPrevious, &QToolButton::clicked, this, [this](){
|
||||
find(ui->editFindExpression->text(), false);
|
||||
});
|
||||
connect(ui->buttonFindNext, &QToolButton::clicked, this, [this](){
|
||||
find(ui->editFindExpression->text(), true);
|
||||
});
|
||||
}
|
||||
|
||||
TableBrowser::~TableBrowser()
|
||||
@@ -328,6 +363,7 @@ void TableBrowser::setEnabled(bool enable)
|
||||
ui->actionRefresh->setEnabled(enable);
|
||||
ui->actionPrintTable->setEnabled(enable);
|
||||
ui->editGlobalFilter->setEnabled(enable);
|
||||
ui->actionFind->setEnabled(enable);
|
||||
|
||||
updateInsertDeleteRecordButton();
|
||||
}
|
||||
@@ -379,7 +415,7 @@ void TableBrowser::updateTable()
|
||||
}
|
||||
statusMessage += tr(". Sum: %1; Average: %2; Min: %3; Max: %4").arg(sum).arg(sum/sel.count()).arg(min).arg(max);
|
||||
}
|
||||
};
|
||||
}
|
||||
emit statusMessageRequested(statusMessage);
|
||||
});
|
||||
}
|
||||
@@ -1310,3 +1346,54 @@ void TableBrowser::jumpToRow(const sqlb::ObjectIdentifier& table, QString column
|
||||
ui->dataTable->filterHeader()->setFilter(static_cast<size_t>(column_index-obj->fields.begin()+1), QString("=") + value);
|
||||
updateTable();
|
||||
}
|
||||
|
||||
void TableBrowser::find(const QString& expr, bool forward, bool include_first)
|
||||
{
|
||||
// Get the cell from which the search should be started. If there is a selected cell, use that. If there is no selected cell, start at the first cell.
|
||||
QModelIndex start;
|
||||
if(ui->dataTable->selectionModel()->hasSelection())
|
||||
start = ui->dataTable->selectionModel()->selectedIndexes().front();
|
||||
else
|
||||
start = m_browseTableModel->index(0, 0);
|
||||
|
||||
// Prepare the match flags with all the search settings
|
||||
Qt::MatchFlags flags = Qt::MatchWrap;
|
||||
|
||||
if(ui->checkFindCaseSensitive->isChecked())
|
||||
flags |= Qt::MatchCaseSensitive;
|
||||
|
||||
if(ui->checkFindWholeCell->isChecked())
|
||||
flags |= Qt::MatchFixedString;
|
||||
else
|
||||
flags |= Qt::MatchContains;
|
||||
|
||||
if(ui->checkFindRegEx->isChecked())
|
||||
flags |= Qt::MatchRegExp;
|
||||
|
||||
// Prepare list of columns to search in. We only search in non-hidden rows
|
||||
std::vector<int> column_list;
|
||||
sqlb::ObjectIdentifier tableName = currentlyBrowsedTableName();
|
||||
if(browseTableSettings[tableName].showRowid)
|
||||
column_list.push_back(0);
|
||||
for(int i=1;i<m_browseTableModel->columnCount();i++)
|
||||
{
|
||||
if(browseTableSettings[tableName].hiddenColumns.contains(i) == false)
|
||||
column_list.push_back(i);
|
||||
else if(browseTableSettings[tableName].hiddenColumns[i] == false)
|
||||
column_list.push_back(i);
|
||||
}
|
||||
|
||||
// Perform the actual search using the model class
|
||||
const auto match = m_browseTableModel->nextMatch(start, column_list, expr, flags, !forward, include_first);
|
||||
|
||||
// Select the next match if we found one
|
||||
if(match.isValid()) {
|
||||
ui->dataTable->setCurrentIndex(match);
|
||||
ui->dataTable->scrollTo(match);
|
||||
}
|
||||
// Make the expression control red if no results were found
|
||||
if(match.isValid() || expr == "")
|
||||
ui->editFindExpression->setStyleSheet("");
|
||||
else
|
||||
ui->editFindExpression->setStyleSheet("QLineEdit {color: white; background-color: rgb(255, 102, 102)}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user