Big cleanup

This commit is contained in:
eelke 2022-05-26 08:25:31 +02:00
parent d3080a08bb
commit 8b671090a0
55 changed files with 214 additions and 3967 deletions

View file

@ -3,6 +3,9 @@
#include <QWidget>
/// Base class for widgets that are used as on the tabs in DatabaseWindow
/// if a widget does not inherit from managed pase DatabaseWindow will
/// fallback on default behaviour.
class ManagedPage: public QWidget
{
Q_OBJECT
@ -11,6 +14,7 @@ public:
virtual ~ManagedPage() {}
/// Tells DatabaseWindow if it is ok to close this tab
virtual bool CanClose(bool prompt_user) = 0;
};

View file

@ -1,63 +0,0 @@
#include "Module.h"
#include <set>
using namespace Leon;
void ModuleRegistry::registerModule(Module *module)
{
modules.insert(module);
}
ModuleRegistry& Leon::GetModuleRegistry()
{
static ModuleRegistry registry;
return registry;
}
Module::Module() = default;
ModuleInstance::ModuleInstance()
{
GetModuleRegistry().registerModule(this);
}
//class QueryModule: public ModuleInstance {
//public:
// QueryModule();
// virtual QString getName() const override;
// virtual CommandContainer getCommands() const override;
//private:
//// CommandContainer commands;
// void createNewQueryTab();
//};
//QueryModule::QueryModule()
//{
//// commands = {
//// std::make_shared<Command<>>("New SQL file", "", createNewQueryTab)
//// ->setHint("")
//// ->setDescription("")
//// ->setShortCut(Qt::CTRL + Qt::Key_N)
//// ->addOnToolbar("standard", "")
//// ->setMenuPath("file")
//// };
//}
//QString QueryModule::getName() const
//{
// return "Query Module";
//}
////QueryModule::CommandContainer QueryModule::getCommands() const
////{
//// return commands;
////}
////QueryModule theQueryModuleInstance;

View file

@ -1,120 +0,0 @@
#ifndef MODULE_H
#define MODULE_H
#include "AbstractCommand.h"
#include <QKeySequence>
#include <QString>
#include <boost/container/small_vector.hpp>
#include <memory>
#include <unordered_set>
#include <vector>
class QAction;
namespace Leon {
class Module;
class ModuleRegistry {
public:
using ModuleContainer = std::unordered_set<Module*>;
using Iterator = ModuleContainer::iterator;
Iterator begin() { return modules.begin(); }
Iterator end() { return modules.end(); }
void registerModule(Module *module);
private:
ModuleContainer modules;
};
ModuleRegistry& GetModuleRegistry();
template <typename Func>
class Command: public AbstractCommand {
public:
Command(QString caption, QString iconpath, Func f);
Command& setHint(QString hint);
Command& setDescription(QString description);
Command& setShortCut(QKeySequence shortcut);
Command& addOnToolbar(QString toolbar, QString group);
Command& setMenuPath(QString menu);
// action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this);
// action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// connect(action, &QAction::triggered, this, &QueryTab::save);
// actions.push_back(action);
private:
mutable QAction *action = nullptr;
};
/// Abstract interface for retrieving information about a subsystem
///
/// Each module should derive a class From ModuleInstance and implement
/// the abstract methods declared in this interface. Don't do to much in your constructor
/// as it might be called very early in the startup of the program
class Module
{
public:
using AbstractCommandSptr = std::shared_ptr<AbstractCommand>;
using CommandContainer = std::vector<AbstractCommand>;
Module();
// getGlobalActions
virtual QString getName() const = 0;
virtual CommandContainer getCommands() const = 0;
};
/// Adds auto registration to Module so not each
/// module has to implement registration
class ModuleInstance: public Module {
protected:
ModuleInstance();
};
class Path {
public:
explicit Path(QString p)
{
int ofs = 0;
if (p.isEmpty())
return;
if (p[0] == '/')
++ofs;
while (true) {
int i = p.indexOf('/', ofs);
if (i >= ofs) {
path.push_back(p.mid(ofs, i - ofs));
ofs = i+1;
}
else {
path.push_back(p.right(ofs));
break;
}
}
}
int getDepth() const { return path.size(); }
QString getElem(int i) const { return path.at(i); }
private:
using PathContainer = boost::container::small_vector<QString, 3>;
PathContainer path;
};
}
#endif // MODULE_H

View file

@ -1,33 +0,0 @@
#include "NamespaceFilterWidget.h"
#include "ui_NamespaceFilterWidget.h"
#include "NamespaceItemModel.h"
NamespaceFilterWidget::NamespaceFilterWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::NamespaceFilterWidget)
{
ui->setupUi(this);
m_namespaceItemModel = new NamespaceItemModel(this);
ui->treeView->setModel(m_namespaceItemModel);
//ui->treeView->setModelColumn(0);
}
NamespaceFilterWidget::~NamespaceFilterWidget()
{
delete ui;
}
void NamespaceFilterWidget::init(std::shared_ptr<const PgNamespaceContainer> nsc)
{
m_namespaceItemModel->init(nsc);
ui->treeView->expandAll();
}
const NamespaceItemModel* NamespaceFilterWidget::getModel() const
{
return m_namespaceItemModel;
}

View file

@ -1,36 +0,0 @@
#ifndef NAMESPACEFILTERWIDGET_H
#define NAMESPACEFILTERWIDGET_H
#include "Pgsql_Declare.h"
#include <QWidget>
#include <memory>
#include <set>
namespace Ui {
class NamespaceFilterWidget;
}
class NamespaceItemModel;
class PgNamespaceContainer;
class NamespaceFilterWidget : public QWidget
{
Q_OBJECT
public:
explicit NamespaceFilterWidget(QWidget *parent = 0);
~NamespaceFilterWidget();
void init(std::shared_ptr<const PgNamespaceContainer> nsc);
const NamespaceItemModel* getModel() const;
//signals:
// void onFilterChange();
private:
Ui::NamespaceFilterWidget *ui;
NamespaceItemModel *m_namespaceItemModel = nullptr;
};
#endif // NAMESPACEFILTERWIDGET_H

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NamespaceFilterWidget</class>
<widget class="QWidget" name="NamespaceFilterWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>698</width>
<height>611</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true"/>
</item>
<item>
<widget class="QTreeView" name="treeView">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,9 +0,0 @@
#include "NotificationListWidget.h"
#include <QListView>
NotificationListWidget::NotificationListWidget()
: m_notificationList(new QListView(this))
{
}

View file

@ -1,22 +0,0 @@
#ifndef NOTIFICATIONLISTWIDGET_H
#define NOTIFICATIONLISTWIDGET_H
#include <QWidget>
class QListView;
class QTextEdit;
class Notification;
class NotificationListModel;
class NotificationListWidget: QWidget {
public:
NotificationListWidget();
private:
QListView *m_notificationList = nullptr;
QTextEdit *m_detailMessage;
NotificationListModel *m_notificationListModel = nullptr;
};
#endif // NOTIFICATIONLISTWIDGET_H

View file

@ -1,27 +0,0 @@
#include "NotificationModel.h"
#include "NotificationService.h"
NotificationModel::NotificationModel()
{
}
int NotificationModel::rowCount(const QModelIndex &parent) const
{
return m_notifications->count();
}
int NotificationModel::columnCount(const QModelIndex &) const
{
return static_cast<int>(Col::Count);
}
QVariant NotificationModel::data(const QModelIndex &index, int role) const
{
return {};
}
QVariant NotificationModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return {};
}

View file

@ -1,31 +0,0 @@
#ifndef NOTIFICATIONMODEL_H
#define NOTIFICATIONMODEL_H
#include <QAbstractTableModel>
#include <memory>
class NotificationService;
class NotificationModel: public QAbstractTableModel {
public:
enum class Col {
Severity,
ShortMessage,
DetailMessage,
Count // SHOULD BE LAST
};
NotificationModel();
virtual int rowCount(const QModelIndex &parent = {}) const override;
virtual int columnCount(const QModelIndex &parent = {}) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
private:
std::shared_ptr<NotificationService> m_notifications;
};
#endif // NOTIFICATIONMODEL_H

View file

@ -1,59 +0,0 @@
#include "NotificationService.h"
namespace {
class registerMetaTypes {
public:
registerMetaTypes()
{
qRegisterMetaType<NotificationSeverity>();
qRegisterMetaType<Notification>();
}
} registerMetaTypes_instance;
}
std::shared_ptr<NotificationService> NotificationService::s_instance;
std::shared_ptr<NotificationService> NotificationService::instance()
{
if (!s_instance) {
s_instance = std::make_shared<NotificationService>();
}
return s_instance;
}
NotificationService::NotificationService()
{
}
void NotificationService::addInformational(const QString &msg, const QString &detail)
{
add(NotificationSeverity::Informational, msg, detail);
}
void NotificationService::addWarning(const QString &msg, const QString &detail)
{
add(NotificationSeverity::Warning, msg, detail);
}
void NotificationService::addError(const QString &msg, const QString &detail)
{
add(NotificationSeverity::Error, msg, detail);
}
void NotificationService::add(NotificationSeverity severity, const QString &msg, const QString &detail)
{
// m_notifications.push_back({ severity, msg, detail });
}
int NotificationService::count() const
{
return m_notifications.size();
}
const Notification& NotificationService::notification(int index)
{
return m_notifications.at(index);
}

View file

@ -1,65 +0,0 @@
#ifndef NOTIFICATIONSERVICE_H
#define NOTIFICATIONSERVICE_H
#include <QObject>
#include <QString>
#include <QVector>
#include <memory>
#include <shared_mutex>
enum NotificationSeverity {
Informational, ///< Use for notifications of succesful completion and other things the user likely does not need to be bothered with
Warning, ///<
Error, ///< Use for failures like not being able to save the users data
Critical ///< Don't think you should ever need this in a correct program....
};
class Notification {
public:
Notification() = default;
Notification(int64_t id, NotificationSeverity severity, const QString &msg, const QString &detail = {});
int64_t id() const { return m_id; }
NotificationSeverity severity() const { return m_severity; }
QString shortMessage() const { return m_shortMessage; }
QString detailMessage() const { return m_detailMessage; }
private:
int64_t m_id = 0;
NotificationSeverity m_severity = NotificationSeverity::Informational;
QString m_shortMessage;
QString m_detailMessage;
};
class NotificationService: public QObject {
Q_OBJECT
public:
static std::shared_ptr<NotificationService> instance();
NotificationService();
void addInformational(const QString &msg, const QString &detail = {});
void addWarning(const QString &msg, const QString &detail = {});
void addError(const QString &msg, const QString &detail = {});
void add(NotificationSeverity severity, const QString &msg, const QString &detail = {});
/// Returns the number of notifications
int count() const;
const Notification& notification(int index);
signals:
void onNewNotification(const Notification &notification);
private:
static std::shared_ptr<NotificationService> s_instance;
using NotificationContainer = QVector<Notification>;
std::shared_mutex m_nofiticationsMutex;
NotificationContainer m_notifications;
};
Q_DECLARE_METATYPE(NotificationSeverity)
Q_DECLARE_METATYPE(Notification)
#endif // NOTIFICATIONSERVICE_H

View file

@ -63,9 +63,6 @@ SOURCES += main.cpp\
ConnectionConfigurationWidget.cpp \
ConnectionController.cpp \
ManagedPage.cpp \
NotificationListWidget.cpp \
NotificationModel.cpp \
NotificationService.cpp \
PgDumpOutputHighlighter.cpp \
CreateDatabaseDialog.cpp \
ConnectionManagerWindow.cpp \
@ -79,9 +76,7 @@ SOURCES += main.cpp\
OpenDatabase.cpp \
ProcessStdioWidget.cpp \
ResultTableModelUtil.cpp \
NamespaceFilterWidget.cpp \
NamespaceItemModel.cpp \
Module.cpp \
PropertyProxyModel.cpp \
CodeGenerator.cpp \
UserConfiguration.cpp \
@ -140,9 +135,6 @@ HEADERS += \
ConnectionController.h \
IDatabaseWindow.h \
ManagedPage.h \
NotificationListWidget.h \
NotificationModel.h \
NotificationService.h \
PgDumpOutputHighlighter.h \
CreateDatabaseDialog.h \
ConnectionManagerWindow.h \
@ -156,9 +148,7 @@ HEADERS += \
OpenDatabase.h \
ProcessStdioWidget.h \
ResultTableModelUtil.h \
NamespaceFilterWidget.h \
NamespaceItemModel.h \
Module.h \
AbstractCommand.h \
PropertyProxyModel.h \
CustomDataRole.h \
@ -182,7 +172,6 @@ FORMS += \
TuplesResultWidget.ui \
querytool/QueryTab.ui \
ProcessStdioWidget.ui \
NamespaceFilterWidget.ui \
crud/CrudTab.ui \
CodeGenerator.ui \
widgets/SingleRecordWidget.ui

View file

@ -23,10 +23,6 @@ void StopWatch::stop()
void StopWatch::updateTimer()
{
// auto nu = std::chrono::steady_clock::now();
// std::chrono::duration<float, std::milli> diff = nu - m_startTime;
// elapsedTime = diff;
// m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count()));
if (m_elapsed.isValid()) {
qint64 ms = m_elapsed.elapsed();
if (m_output) {