forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dialog and foreground configuration for conditional formats
A new dialog for editing conditional formats that can be invoked from the filter line editor or from the data browser contextual menus. The dialog allows adding and removing conditional formats, changing the priority order and editing foreground colour, background colour and filter condition. The conditional formats have been expanded to allow defining the foreground colour. By default is the setting configured by user. This is a continuation of the functionality introduced in PR sqlitebrowser#1503.
- Loading branch information
Showing
21 changed files
with
466 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "CondFormatManager.h" | ||
#include "ui_CondFormatManager.h" | ||
#include "CondFormat.h" | ||
#include "Settings.h" | ||
|
||
#include "QColorDialog" | ||
|
||
CondFormatManager::CondFormatManager(const QVector<CondFormat>& condFormats, const QString& encoding, QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::CondFormatManager), | ||
m_condFormats(condFormats), | ||
m_encoding(encoding) | ||
{ | ||
ui->setupUi(this); | ||
|
||
for(const CondFormat& aCondFormat : condFormats) | ||
addItem(aCondFormat); | ||
|
||
ui->tableCondFormats->setEditTriggers(QAbstractItemView::AllEditTriggers); | ||
|
||
connect(ui->buttonAdd, SIGNAL(clicked(bool)), this, SLOT(addNewItem())); | ||
connect(ui->buttonRemove, SIGNAL(clicked(bool)), this, SLOT(removeItem())); | ||
|
||
connect(ui->buttonDown, SIGNAL(clicked(bool)), this, SLOT(downItem())); | ||
connect(ui->buttonUp, SIGNAL(clicked(bool)), this, SLOT(upItem())); | ||
|
||
connect(ui->tableCondFormats, &QTreeWidget::itemDoubleClicked, this, &CondFormatManager::itemDoubleClicked); | ||
} | ||
|
||
CondFormatManager::~CondFormatManager() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void CondFormatManager::addNewItem() | ||
{ | ||
CondFormat newCondFormat("", QColor(Settings::getValue("databrowser", "reg_fg_colour").toString()), | ||
m_condFormatPalette.nextSerialColor(Palette::appHasDarkTheme()), | ||
m_encoding); | ||
addItem(newCondFormat); | ||
} | ||
|
||
void CondFormatManager::addItem(const CondFormat& aCondFormat) | ||
{ | ||
int i = ui->tableCondFormats->topLevelItemCount(); | ||
QTreeWidgetItem *newItem = new QTreeWidgetItem({aCondFormat.foregroundColor().name(), | ||
aCondFormat.backgroundColor().name(), aCondFormat.filter()}); | ||
newItem->setForeground(ColumnForeground, aCondFormat.foregroundColor()); | ||
newItem->setBackground(ColumnForeground, aCondFormat.foregroundColor()); | ||
newItem->setForeground(ColumnBackground, aCondFormat.backgroundColor()); | ||
newItem->setBackground(ColumnBackground, aCondFormat.backgroundColor()); | ||
ui->tableCondFormats->insertTopLevelItem(i, newItem); | ||
ui->tableCondFormats->openPersistentEditor(newItem, ColumnFilter); | ||
} | ||
|
||
void CondFormatManager::removeItem() | ||
{ | ||
QTreeWidgetItem* item = ui->tableCondFormats->takeTopLevelItem(ui->tableCondFormats->currentIndex().row()); | ||
delete item; | ||
} | ||
|
||
void CondFormatManager::upItem() | ||
{ | ||
if (ui->tableCondFormats->selectedItems().isEmpty()) return; | ||
|
||
int selectedRow = ui->tableCondFormats->currentIndex().row(); | ||
if(selectedRow == 0) | ||
return; | ||
|
||
QTreeWidgetItem* item; | ||
item = ui->tableCondFormats->takeTopLevelItem(selectedRow); | ||
ui->tableCondFormats->insertTopLevelItem(selectedRow-1, item); | ||
ui->tableCondFormats->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(selectedRow-1, | ||
ui->tableCondFormats->currentIndex().column())); | ||
} | ||
|
||
void CondFormatManager::downItem() | ||
{ | ||
if (ui->tableCondFormats->selectedItems().isEmpty()) 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->setCurrentIndex(ui->tableCondFormats->currentIndex().sibling(selectedRow+1, | ||
ui->tableCondFormats->currentIndex().column())); | ||
} | ||
|
||
QVector<CondFormat> CondFormatManager::getCondFormats() | ||
{ | ||
QVector<CondFormat> result; | ||
for (int i = 0; i < ui->tableCondFormats->topLevelItemCount(); ++i) | ||
{ | ||
QTreeWidgetItem* item = ui->tableCondFormats->topLevelItem(i); | ||
CondFormat aCondFormat(item->text(ColumnFilter), | ||
item->background(ColumnForeground).color(), | ||
item->background(ColumnBackground).color(), m_encoding); | ||
result.append(aCondFormat); | ||
} | ||
return result; | ||
} | ||
|
||
|
||
void CondFormatManager::itemDoubleClicked(QTreeWidgetItem* item, int column) | ||
{ | ||
switch (column) { | ||
case ColumnForeground: | ||
case ColumnBackground: { | ||
QColor color = QColorDialog::getColor(item->background(column).color(), this); | ||
if(color.isValid()) { | ||
item->setTextColor(column, color); | ||
item->setBackgroundColor(column, color); | ||
item->setText(column, color.name()); | ||
} | ||
break; | ||
} | ||
case ColumnFilter: | ||
// Nothing to do | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef CONDFORMATMANAGER_H | ||
#define CONDFORMATMANAGER_H | ||
|
||
#include <QDialog> | ||
|
||
#include "Palette.h" | ||
|
||
namespace Ui { | ||
class CondFormatManager; | ||
} | ||
|
||
class CondFormat; | ||
class QTreeWidgetItem; | ||
|
||
class CondFormatManager : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit CondFormatManager(const QVector<CondFormat>& condFormats, const QString& encoding, QWidget *parent = nullptr); | ||
~CondFormatManager() override; | ||
|
||
QVector<CondFormat> getCondFormats(); | ||
private: | ||
enum Columns { | ||
ColumnForeground = 0, | ||
ColumnBackground = 1, | ||
ColumnFilter = 2 | ||
}; | ||
Ui::CondFormatManager *ui; | ||
QVector<CondFormat> m_condFormats; | ||
Palette m_condFormatPalette; | ||
QString m_encoding; | ||
|
||
private slots: | ||
void addNewItem(); | ||
void addItem(const CondFormat& aCondFormat); | ||
void removeItem(); | ||
void upItem(); | ||
void downItem(); | ||
|
||
public slots: | ||
void itemDoubleClicked(QTreeWidgetItem* item, int column); | ||
}; | ||
|
||
#endif // CONDFORMATMANAGER_H |
Oops, something went wrong.