Moved many components into shared libraries of DbSoftware
This commit is contained in:
69
CMakeLists.txt
Normal file
69
CMakeLists.txt
Normal file
@ -0,0 +1,69 @@
|
||||
find_package(Qt5Core CONFIG REQUIRED)
|
||||
find_package(Qt5Gui CONFIG REQUIRED)
|
||||
find_package(Qt5Widgets CONFIG REQUIRED)
|
||||
find_package(Qt5Network CONFIG REQUIRED)
|
||||
find_package(Qt5Sql CONFIG REQUIRED)
|
||||
find_package(Qt5Charts CONFIG REQUIRED)
|
||||
|
||||
set(HEADERS
|
||||
mainwindow.h
|
||||
wizard/importwizard.h
|
||||
wizard/intropage.h
|
||||
wizard/databasepage.h
|
||||
wizard/importtypepage.h
|
||||
wizard/localimportpage.h
|
||||
wizard/conclusionpage.h
|
||||
wizard/remoteimportoverviewpage.h
|
||||
wizard/tablespage.h
|
||||
threads/tablecreatorthread.h
|
||||
threads/remotescannerthread.h
|
||||
wizard/remoteimportscanpage.h
|
||||
common.h
|
||||
threads/importthread.h
|
||||
wizard/importprogresspage.h
|
||||
dialogs/opendialog.h
|
||||
dialogs/graphdialog.h
|
||||
models/logmodel.h
|
||||
threads/projectopenerthread.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
wizard/importwizard.cpp
|
||||
wizard/intropage.cpp
|
||||
wizard/databasepage.cpp
|
||||
wizard/importtypepage.cpp
|
||||
wizard/localimportpage.cpp
|
||||
wizard/conclusionpage.cpp
|
||||
wizard/remoteimportoverviewpage.cpp
|
||||
wizard/tablespage.cpp
|
||||
threads/tablecreatorthread.cpp
|
||||
threads/remotescannerthread.cpp
|
||||
wizard/remoteimportscanpage.cpp
|
||||
threads/importthread.cpp
|
||||
wizard/importprogresspage.cpp
|
||||
dialogs/opendialog.cpp
|
||||
dialogs/graphdialog.cpp
|
||||
models/logmodel.cpp
|
||||
threads/projectopenerthread.cpp
|
||||
)
|
||||
|
||||
set(FORMS
|
||||
mainwindow.ui
|
||||
dialogs/opendialog.ui
|
||||
wizard/intropage.ui
|
||||
wizard/databasepage.ui
|
||||
dialogs/graphdialog.ui
|
||||
wizard/tablespage.ui
|
||||
wizard/importtypepage.ui
|
||||
wizard/localimportpage.ui
|
||||
)
|
||||
|
||||
set(RESOURCES
|
||||
loganalyzer_resources.qrc
|
||||
)
|
||||
|
||||
add_executable(loganalyzer ${HEADERS} ${SOURCES} ${FORMS} ${RESOURCES})
|
||||
|
||||
target_link_libraries(loganalyzer stdc++ Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network Qt5::Sql Qt5::Charts dbcorelib dbguilib)
|
@ -25,7 +25,17 @@ std::unique_ptr<Project> &OpenDialog::project()
|
||||
void OpenDialog::submit()
|
||||
{
|
||||
auto project = std::make_unique<Project>();
|
||||
project->database = m_ui->databaseWidget->createConnection();
|
||||
project->database = QSqlDatabase::addDatabase(m_ui->databaseWidget->driver());
|
||||
|
||||
if (project->database.driverName() == "QSQLITE")
|
||||
project->database.setDatabaseName(m_ui->databaseWidget->sqliteFilepath());
|
||||
else
|
||||
{
|
||||
project->database.setHostName(m_ui->databaseWidget->mysqlHostname());
|
||||
project->database.setUserName(m_ui->databaseWidget->mysqlUsername());
|
||||
project->database.setPassword(m_ui->databaseWidget->mysqlPassword());
|
||||
project->database.setDatabaseName(m_ui->databaseWidget->mysqlDatabase());
|
||||
}
|
||||
|
||||
if (!project->database.open())
|
||||
{
|
||||
|
@ -1,77 +0,0 @@
|
||||
#include "gzipdevice.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
GzipDevice::GzipDevice(QFile &file, QObject *parent) :
|
||||
QIODevice(parent),
|
||||
m_file(file)
|
||||
{
|
||||
if (!m_file.isOpen())
|
||||
throw std::runtime_error("file is not open");
|
||||
|
||||
setOpenMode(QIODevice::ReadOnly);
|
||||
|
||||
// Prepare inflater status
|
||||
strm.zalloc = Z_NULL;
|
||||
strm.zfree = Z_NULL;
|
||||
strm.opaque = Z_NULL;
|
||||
strm.avail_in = 0;
|
||||
strm.next_in = Z_NULL;
|
||||
|
||||
// Initialize inflater
|
||||
m_result = inflateInit2(&strm, 15 + 16);
|
||||
if (m_result != Z_OK)
|
||||
throw std::runtime_error("could not init z_stream");
|
||||
}
|
||||
|
||||
GzipDevice::~GzipDevice()
|
||||
{
|
||||
inflateEnd(&strm);
|
||||
}
|
||||
|
||||
bool GzipDevice::isSequential() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GzipDevice::atEnd() const
|
||||
{
|
||||
return m_result == Z_STREAM_END;
|
||||
}
|
||||
|
||||
qint64 GzipDevice::readData(char *data, qint64 maxlen)
|
||||
{
|
||||
if (strm.avail_in == 0)
|
||||
{
|
||||
strm.next_in = reinterpret_cast<unsigned char *>(m_readBuffer);
|
||||
strm.avail_in = m_file.read(m_readBuffer, m_readBufferSize);
|
||||
}
|
||||
|
||||
strm.next_out = reinterpret_cast<unsigned char*>(data);
|
||||
strm.avail_out = maxlen;
|
||||
|
||||
m_result = inflate(&strm, Z_NO_FLUSH);
|
||||
|
||||
switch (m_result) {
|
||||
case Z_NEED_DICT:
|
||||
throw std::runtime_error("decompression failed: Z_NEED_DICT");
|
||||
case Z_DATA_ERROR:
|
||||
throw std::runtime_error("decompression failed: Z_DATA_ERROR");
|
||||
case Z_MEM_ERROR:
|
||||
throw std::runtime_error("decompression failed: Z_MEM_ERROR");
|
||||
case Z_STREAM_ERROR:
|
||||
throw std::runtime_error("decompression failed: Z_STREAM_ERROR");
|
||||
}
|
||||
|
||||
return maxlen-strm.avail_out;
|
||||
}
|
||||
|
||||
qint64 GzipDevice::writeData(const char *data, qint64 len)
|
||||
{
|
||||
Q_UNUSED(data)
|
||||
Q_UNUSED(len)
|
||||
throw std::runtime_error("writing not allowed!");
|
||||
return -1;
|
||||
}
|
28
gzipdevice.h
28
gzipdevice.h
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QIODevice>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
class QFile;
|
||||
|
||||
class GzipDevice : public QIODevice
|
||||
{
|
||||
public:
|
||||
GzipDevice(QFile &file, QObject *parent = nullptr);
|
||||
~GzipDevice() override;
|
||||
|
||||
bool isSequential() const override;
|
||||
bool atEnd() const override;
|
||||
|
||||
protected:
|
||||
qint64 readData(char *data, qint64 maxlen) override;
|
||||
qint64 writeData(const char *data, qint64 len) override;
|
||||
|
||||
private:
|
||||
QFile &m_file;
|
||||
static constexpr std::size_t m_readBufferSize { 32 * 1024 };
|
||||
char m_readBuffer[m_readBufferSize];
|
||||
z_stream strm;
|
||||
int m_result;
|
||||
};
|
@ -1,83 +0,0 @@
|
||||
QT += core gui widgets network sql charts
|
||||
|
||||
TARGET = loganalyzer
|
||||
TEMPLATE = app
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
|
||||
CONFIG += c++14
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O1
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE *= -O3
|
||||
QMAKE_CXXFLAGS_RELEASE -= -march=x86-64
|
||||
QMAKE_CXXFLAGS_RELEASE -= -mtune=generic
|
||||
QMAKE_CXXFLAGS_RELEASE *= -march=native
|
||||
QMAKE_CXXFLAGS_RELEASE *= -mtune=native
|
||||
|
||||
LIBS += -lz
|
||||
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp \
|
||||
wizard/importwizard.cpp \
|
||||
wizard/intropage.cpp \
|
||||
wizard/databasepage.cpp \
|
||||
wizard/importtypepage.cpp \
|
||||
wizard/localimportpage.cpp \
|
||||
wizard/conclusionpage.cpp \
|
||||
wizard/remoteimportoverviewpage.cpp \
|
||||
wizard/tablespage.cpp \
|
||||
threads/tablecreatorthread.cpp \
|
||||
models/checklistmodel.cpp \
|
||||
threads/remotescannerthread.cpp \
|
||||
wizard/remoteimportscanpage.cpp \
|
||||
threads/importthread.cpp \
|
||||
wizard/importprogresspage.cpp \
|
||||
dialogs/opendialog.cpp \
|
||||
widgets/fileselectionwidget.cpp \
|
||||
widgets/databasewidget.cpp \
|
||||
gzipdevice.cpp \
|
||||
dialogs/graphdialog.cpp \
|
||||
models/logmodel.cpp \
|
||||
models/progressmodel.cpp \
|
||||
threads/projectopenerthread.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
wizard/importwizard.h \
|
||||
wizard/intropage.h \
|
||||
wizard/databasepage.h \
|
||||
wizard/importtypepage.h \
|
||||
wizard/localimportpage.h \
|
||||
wizard/conclusionpage.h \
|
||||
wizard/remoteimportoverviewpage.h \
|
||||
wizard/tablespage.h \
|
||||
threads/tablecreatorthread.h \
|
||||
models/checklistmodel.h \
|
||||
threads/remotescannerthread.h \
|
||||
wizard/remoteimportscanpage.h \
|
||||
common.h \
|
||||
threads/importthread.h \
|
||||
wizard/importprogresspage.h \
|
||||
dialogs/opendialog.h \
|
||||
widgets/fileselectionwidget.h \
|
||||
widgets/databasewidget.h \
|
||||
gzipdevice.h \
|
||||
dialogs/graphdialog.h \
|
||||
models/logmodel.h \
|
||||
models/progressmodel.h \
|
||||
threads/projectopenerthread.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui \
|
||||
dialogs/opendialog.ui \
|
||||
widgets/fileselectionwidget.ui \
|
||||
widgets/databasewidget.ui \
|
||||
wizard/intropage.ui \
|
||||
wizard/databasepage.ui \
|
||||
dialogs/graphdialog.ui \
|
||||
wizard/tablespage.ui \
|
||||
wizard/importtypepage.ui \
|
||||
wizard/localimportpage.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
@ -1,182 +0,0 @@
|
||||
#include "checklistmodel.h"
|
||||
|
||||
ChecklistModel::ChecklistModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ChecklistModel::ChecklistModel(const QStringList &items, QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
for (const auto &item : items)
|
||||
m_items.append({ item, item, true });
|
||||
}
|
||||
|
||||
ChecklistModel::ChecklistModel(const QList<ChecklistItem> &items, QObject *parent) :
|
||||
QAbstractListModel(parent),
|
||||
m_items(items)
|
||||
{
|
||||
}
|
||||
|
||||
const QList<ChecklistModel::ChecklistItem> &ChecklistModel::items() const
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
void ChecklistModel::setItems(const QList<ChecklistItem> &items)
|
||||
{
|
||||
emit beginResetModel();
|
||||
|
||||
m_items = items;
|
||||
|
||||
emit endResetModel();
|
||||
}
|
||||
|
||||
void ChecklistModel::setItems(const QStringList &items)
|
||||
{
|
||||
emit beginResetModel();
|
||||
|
||||
m_items.clear();
|
||||
|
||||
for (const auto &item : items)
|
||||
m_items.append({ item, item, true });
|
||||
|
||||
emit endResetModel();
|
||||
}
|
||||
|
||||
QStringList ChecklistModel::itemTexts() const
|
||||
{
|
||||
QStringList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
items.append(item.displayText);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QVariantList ChecklistModel::itemDatas() const
|
||||
{
|
||||
QVariantList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
items.append(item.data);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QList<ChecklistModel::ChecklistItem> ChecklistModel::enabledItems() const
|
||||
{
|
||||
QList<ChecklistModel::ChecklistItem> items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (item.checked)
|
||||
items.append(item);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QList<ChecklistModel::ChecklistItem> ChecklistModel::disabledItems() const
|
||||
{
|
||||
QList<ChecklistModel::ChecklistItem> items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (!item.checked)
|
||||
items.append(item);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QStringList ChecklistModel::enabledTexts() const
|
||||
{
|
||||
QStringList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (item.checked)
|
||||
items.append(item.displayText);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QStringList ChecklistModel::disabledTexts() const
|
||||
{
|
||||
QStringList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (!item.checked)
|
||||
items.append(item.displayText);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QVariantList ChecklistModel::enabledItemDatas() const
|
||||
{
|
||||
QVariantList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (item.checked)
|
||||
items.append(item.data);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QVariantList ChecklistModel::disabledItemDatas() const
|
||||
{
|
||||
QVariantList items;
|
||||
|
||||
for (const auto &item : m_items)
|
||||
if (!item.checked)
|
||||
items.append(item.data);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
int ChecklistModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_items.count();
|
||||
}
|
||||
|
||||
QVariant ChecklistModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_items.size())
|
||||
return {};
|
||||
|
||||
const auto &item = m_items.at(index.row());
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole: return item.displayText;
|
||||
case Qt::EditRole: return item.data;
|
||||
case Qt::CheckStateRole: return item.checked ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ChecklistModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_items.size())
|
||||
return false;
|
||||
|
||||
auto &item = m_items[index.row()];
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::CheckStateRole:
|
||||
item.checked = value.toBool();
|
||||
emit dataChanged(index, index, { Qt::CheckStateRole });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags ChecklistModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QAbstractListModel::flags(index);
|
||||
|
||||
return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QList>
|
||||
|
||||
class Q_CORE_EXPORT ChecklistModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct ChecklistItem
|
||||
{
|
||||
QString displayText;
|
||||
QVariant data;
|
||||
bool checked;
|
||||
};
|
||||
|
||||
explicit ChecklistModel(QObject *parent = nullptr);
|
||||
explicit ChecklistModel(const QStringList &items, QObject *parent = nullptr);
|
||||
explicit ChecklistModel(const QList<ChecklistItem> &strings, QObject *parent = nullptr);
|
||||
|
||||
const QList<ChecklistItem> &items() const;
|
||||
void setItems(const QList<ChecklistItem> &items);
|
||||
void setItems(const QStringList &items);
|
||||
|
||||
QStringList itemTexts() const;
|
||||
QVariantList itemDatas() const;
|
||||
QList<ChecklistItem> enabledItems() const;
|
||||
QList<ChecklistItem> disabledItems() const;
|
||||
QStringList enabledTexts() const;
|
||||
QStringList disabledTexts() const;
|
||||
QVariantList enabledItemDatas() const;
|
||||
QVariantList disabledItemDatas() const;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
QList<ChecklistItem> m_items;
|
||||
};
|
@ -1,148 +0,0 @@
|
||||
#include "progressmodel.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
ProgressModel::ProgressModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
|
||||
}
|
||||
|
||||
ProgressModel::ProgressModel(const QStringList &items, QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
|
||||
|
||||
m_items.reserve(items.count());
|
||||
for (const auto &item : items)
|
||||
m_items.append({ item, Item::Status::None });
|
||||
}
|
||||
|
||||
ProgressModel::ProgressModel(const QVector<ProgressModel::Item> &items, QObject *parent) :
|
||||
QAbstractListModel(parent),
|
||||
m_items(items)
|
||||
{
|
||||
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
|
||||
|
||||
if (anyLoading())
|
||||
m_movieLoading.start();
|
||||
}
|
||||
|
||||
const QVector<ProgressModel::Item> &ProgressModel::items() const
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
void ProgressModel::setItems(const QStringList &items)
|
||||
{
|
||||
emit beginResetModel();
|
||||
m_items.clear();
|
||||
m_items.reserve(items.count());
|
||||
for (const auto &item : items)
|
||||
m_items.append({ item, Item::Status::None });
|
||||
emit endResetModel();
|
||||
|
||||
m_movieLoading.stop();
|
||||
}
|
||||
|
||||
void ProgressModel::setItems(const QVector<ProgressModel::Item> &items)
|
||||
{
|
||||
emit beginResetModel();
|
||||
m_items = items;
|
||||
emit endResetModel();
|
||||
|
||||
updateMovieStatus();
|
||||
}
|
||||
|
||||
void ProgressModel::setText(int row, const QString &text)
|
||||
{
|
||||
m_items[row].text = text;
|
||||
|
||||
const auto index = createIndex(row, 0);
|
||||
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
||||
}
|
||||
|
||||
void ProgressModel::setStatus(int row, ProgressModel::Item::Status status)
|
||||
{
|
||||
m_items[row].status = status;
|
||||
|
||||
const auto index = createIndex(row, 0);
|
||||
emit dataChanged(index, index, { Qt::DecorationRole });
|
||||
|
||||
if (status == Item::Status::Loading)
|
||||
m_movieLoading.start();
|
||||
else
|
||||
updateMovieStatus();
|
||||
}
|
||||
|
||||
void ProgressModel::clearItems()
|
||||
{
|
||||
emit beginResetModel();
|
||||
m_items.clear();
|
||||
emit endResetModel();
|
||||
|
||||
m_movieLoading.stop();
|
||||
}
|
||||
|
||||
int ProgressModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_items.count();
|
||||
}
|
||||
|
||||
QVariant ProgressModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_items.size())
|
||||
return {};
|
||||
|
||||
const auto &item = m_items.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
return item.text;
|
||||
case Qt::DecorationRole:
|
||||
switch (item.status)
|
||||
{
|
||||
case Item::Status::None:
|
||||
return m_pixmapEmpty;
|
||||
case Item::Status::Loading:
|
||||
return m_movieLoading.currentPixmap();
|
||||
case Item::Status::Succeeded:
|
||||
return m_pixmapSucceeded;
|
||||
case Item::Status::Failed:
|
||||
return m_pixmapFailed;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void ProgressModel::frameChanged()
|
||||
{
|
||||
for (auto iter = m_items.constBegin(); iter != m_items.constEnd(); iter++)
|
||||
{
|
||||
if (iter->status == Item::Status::Loading)
|
||||
{
|
||||
const auto index = createIndex(std::distance(m_items.constBegin(), iter), 0);
|
||||
emit dataChanged(index, index, { Qt::DecorationRole });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ProgressModel::anyLoading() const
|
||||
{
|
||||
return std::any_of(m_items.constBegin(), m_items.constEnd(), [](const auto &item){ return item.status == Item::Status::Loading; });
|
||||
}
|
||||
|
||||
void ProgressModel::updateMovieStatus()
|
||||
{
|
||||
if (anyLoading())
|
||||
m_movieLoading.start();
|
||||
else
|
||||
m_movieLoading.stop();
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QPixmap>
|
||||
#include <QMovie>
|
||||
|
||||
class ProgressModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
enum class Status
|
||||
{
|
||||
None,
|
||||
Loading,
|
||||
Succeeded,
|
||||
Failed
|
||||
};
|
||||
|
||||
QString text;
|
||||
Status status;
|
||||
};
|
||||
|
||||
explicit ProgressModel(QObject *parent = nullptr);
|
||||
ProgressModel(const QStringList &items, QObject *parent = nullptr);
|
||||
ProgressModel(const QVector<Item> &items, QObject *parent = nullptr);
|
||||
|
||||
const QVector<Item> &items() const;
|
||||
void setItems(const QStringList &items);
|
||||
void setItems(const QVector<Item> &items);
|
||||
|
||||
void setText(int row, const QString &text);
|
||||
void setStatus(int row, Item::Status status);
|
||||
|
||||
void clearItems();
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
private slots:
|
||||
void frameChanged();
|
||||
|
||||
private:
|
||||
bool anyLoading() const;
|
||||
void updateMovieStatus();
|
||||
|
||||
QVector<Item> m_items;
|
||||
|
||||
const QPixmap m_pixmapSucceeded { ":/loganalyzer/icons/succeeded.png" };
|
||||
const QPixmap m_pixmapFailed { ":/loganalyzer/icons/failed.png" };
|
||||
const QPixmap m_pixmapEmpty { [this](){
|
||||
QPixmap pixmap(m_pixmapSucceeded.size());
|
||||
pixmap.fill();
|
||||
return pixmap;
|
||||
}() };
|
||||
QMovie m_movieLoading { ":/loganalyzer/icons/loading.gif" };
|
||||
};
|
@ -1,105 +0,0 @@
|
||||
#include "databasewidget.h"
|
||||
#include "ui_databasewidget.h"
|
||||
|
||||
DatabaseWidget::DatabaseWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(std::make_unique<Ui::DatabaseWidget>())
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_ui->comboBox->addItem(tr("SQLite"), "QSQLITE");
|
||||
m_ui->comboBox->addItem(tr("MySQL"), "QMYSQL");
|
||||
|
||||
// for debugging
|
||||
setDriver("QMYSQL");
|
||||
setMysqlHostname("sql7.freemysqlhosting.net");
|
||||
setMysqlUsername("sql7285815");
|
||||
setMysqlPassword("BKhysrtqKl");
|
||||
setMysqlDatabase("sql7285815");
|
||||
|
||||
// setMysqlHostname("brunner.ninja");
|
||||
|
||||
// setMysqlHostname("localhost");
|
||||
// setMysqlUsername("logtest");
|
||||
// setMysqlPassword("logtest");
|
||||
// setMysqlDatabase("logtest");
|
||||
}
|
||||
|
||||
DatabaseWidget::~DatabaseWidget() = default;
|
||||
|
||||
QString DatabaseWidget::driver() const
|
||||
{
|
||||
return m_ui->comboBox->currentData().toString();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setDriver(const QString &driver)
|
||||
{
|
||||
m_ui->comboBox->setCurrentIndex(m_ui->comboBox->findData(driver));
|
||||
}
|
||||
|
||||
QString DatabaseWidget::sqliteFilepath() const
|
||||
{
|
||||
return m_ui->fileSelectionWidget->path();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setSqliteFilepath(const QString &sqliteFilepath)
|
||||
{
|
||||
m_ui->fileSelectionWidget->setPath(sqliteFilepath);
|
||||
}
|
||||
|
||||
QString DatabaseWidget::mysqlHostname() const
|
||||
{
|
||||
return m_ui->lineEditHostname->text();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setMysqlHostname(const QString &mysqlHostname)
|
||||
{
|
||||
m_ui->lineEditHostname->setText(mysqlHostname);
|
||||
}
|
||||
|
||||
QString DatabaseWidget::mysqlUsername() const
|
||||
{
|
||||
return m_ui->lineEditUsername->text();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setMysqlUsername(const QString &mysqlUsername)
|
||||
{
|
||||
m_ui->lineEditUsername->setText(mysqlUsername);
|
||||
}
|
||||
|
||||
QString DatabaseWidget::mysqlPassword() const
|
||||
{
|
||||
return m_ui->lineEditPassword->text();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setMysqlPassword(const QString &mysqlPassword)
|
||||
{
|
||||
m_ui->lineEditPassword->setText(mysqlPassword);
|
||||
}
|
||||
|
||||
QString DatabaseWidget::mysqlDatabase() const
|
||||
{
|
||||
return m_ui->lineEditDatabase->text();
|
||||
}
|
||||
|
||||
void DatabaseWidget::setMysqlDatabase(const QString &mysqlDatabase)
|
||||
{
|
||||
m_ui->lineEditDatabase->setText(mysqlDatabase);
|
||||
}
|
||||
|
||||
QSqlDatabase DatabaseWidget::createConnection(const QString &connectionName)
|
||||
{
|
||||
auto db = QSqlDatabase::addDatabase(driver(), connectionName);
|
||||
|
||||
if (db.driverName() == "QSQLITE")
|
||||
db.setDatabaseName(sqliteFilepath());
|
||||
else
|
||||
{
|
||||
db.setHostName(mysqlHostname());
|
||||
db.setUserName(mysqlUsername());
|
||||
db.setPassword(mysqlPassword());
|
||||
db.setDatabaseName(mysqlDatabase());
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class DatabaseWidget; }
|
||||
|
||||
class DatabaseWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatabaseWidget(QWidget *parent = nullptr);
|
||||
~DatabaseWidget() override;
|
||||
|
||||
QString driver() const;
|
||||
void setDriver(const QString &driver);
|
||||
|
||||
QString sqliteFilepath() const;
|
||||
void setSqliteFilepath(const QString &sqliteFilepath);
|
||||
|
||||
QString mysqlHostname() const;
|
||||
void setMysqlHostname(const QString &mysqlHostname);
|
||||
|
||||
QString mysqlUsername() const;
|
||||
void setMysqlUsername(const QString &mysqlUsername);
|
||||
|
||||
QString mysqlPassword() const;
|
||||
void setMysqlPassword(const QString &mysqlPassword);
|
||||
|
||||
QString mysqlDatabase() const;
|
||||
void setMysqlDatabase(const QString &mysqlDatabase);
|
||||
|
||||
QSqlDatabase createConnection(const QString& connectionName = QLatin1String(QSqlDatabase::defaultConnection));
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::DatabaseWidget> m_ui;
|
||||
};
|
@ -1,167 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DatabaseWidget</class>
|
||||
<widget class="QWidget" name="DatabaseWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>175</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="FileSelectionWidget" name="fileSelectionWidget" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEditUsername"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEditHostname"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelHostname">
|
||||
<property name="text">
|
||||
<string><b>Hostname:</b></string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>lineEditHostname</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelUsername">
|
||||
<property name="text">
|
||||
<string><b>Username:</b></string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>lineEditUsername</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelPassword">
|
||||
<property name="text">
|
||||
<string><b>Password:</b></string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>lineEditPassword</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelDatabase">
|
||||
<property name="text">
|
||||
<string><b>Database:</b></string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>lineEditDatabase</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditPassword">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEditDatabase"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>FileSelectionWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgets/fileselectionwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>comboBox</tabstop>
|
||||
<tabstop>lineEditHostname</tabstop>
|
||||
<tabstop>lineEditUsername</tabstop>
|
||||
<tabstop>lineEditPassword</tabstop>
|
||||
<tabstop>lineEditDatabase</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>comboBox</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>stackedWidget</receiver>
|
||||
<slot>setCurrentIndex(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>199</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>199</x>
|
||||
<y>101</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -1,75 +0,0 @@
|
||||
#include "fileselectionwidget.h"
|
||||
#include "ui_fileselectionwidget.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
FileSelectionWidget::FileSelectionWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(std::make_unique<Ui::FileSelectionWidget>()),
|
||||
m_mode(Mode::OpenFile)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
connect(m_ui->lineEdit, &QLineEdit::textChanged, this, &FileSelectionWidget::pathChanged);
|
||||
connect(m_ui->pushButton, &QAbstractButton::pressed, this, &FileSelectionWidget::selectPath);
|
||||
}
|
||||
|
||||
FileSelectionWidget::FileSelectionWidget(const Mode mode, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(std::make_unique<Ui::FileSelectionWidget>()),
|
||||
m_mode(mode)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
connect(m_ui->lineEdit, &QLineEdit::textChanged, this, &FileSelectionWidget::pathChanged);
|
||||
connect(m_ui->pushButton, &QAbstractButton::pressed, this, &FileSelectionWidget::selectPath);
|
||||
}
|
||||
|
||||
FileSelectionWidget::FileSelectionWidget(const Mode mode, const QString &path, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(std::make_unique<Ui::FileSelectionWidget>()),
|
||||
m_mode(mode)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_ui->lineEdit->setText(path);
|
||||
|
||||
connect(m_ui->lineEdit, &QLineEdit::textChanged, this, &FileSelectionWidget::pathChanged);
|
||||
connect(m_ui->pushButton, &QAbstractButton::pressed, this, &FileSelectionWidget::selectPath);
|
||||
}
|
||||
|
||||
FileSelectionWidget::~FileSelectionWidget() = default;
|
||||
|
||||
FileSelectionWidget::Mode FileSelectionWidget::mode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
void FileSelectionWidget::setMode(const FileSelectionWidget::Mode mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
QString FileSelectionWidget::path() const
|
||||
{
|
||||
return m_ui->lineEdit->text();
|
||||
}
|
||||
|
||||
void FileSelectionWidget::setPath(const QString &path)
|
||||
{
|
||||
m_ui->lineEdit->setText(path);
|
||||
}
|
||||
|
||||
void FileSelectionWidget::selectPath()
|
||||
{
|
||||
QString path;
|
||||
switch (m_mode)
|
||||
{
|
||||
case Mode::OpenFile: path = QFileDialog::getOpenFileName(this); break;
|
||||
case Mode::SaveFile: path = QFileDialog::getSaveFileName(this); break;
|
||||
case Mode::ExistingDirectory: path = QFileDialog::getExistingDirectory(this); break;
|
||||
}
|
||||
|
||||
if (!path.isEmpty())
|
||||
m_ui->lineEdit->setText(path);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class FileSelectionWidget; }
|
||||
|
||||
class FileSelectionWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged USER true)
|
||||
|
||||
public:
|
||||
enum class Mode {
|
||||
OpenFile, SaveFile, ExistingDirectory
|
||||
};
|
||||
|
||||
explicit FileSelectionWidget(QWidget *parent = nullptr);
|
||||
FileSelectionWidget(const Mode mode, QWidget *parent = nullptr);
|
||||
FileSelectionWidget(const Mode mode, const QString &path, QWidget *parent = nullptr);
|
||||
~FileSelectionWidget() override;
|
||||
|
||||
Mode mode() const;
|
||||
void setMode(const Mode mode);
|
||||
|
||||
QString path() const;
|
||||
void setPath(const QString &path);
|
||||
|
||||
signals:
|
||||
void pathChanged(const QString &path);
|
||||
|
||||
private slots:
|
||||
void selectPath();
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::FileSelectionWidget> m_ui;
|
||||
Mode m_mode;
|
||||
};
|
@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FileSelectionWidget</class>
|
||||
<widget class="QWidget" name="FileSelectionWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Select...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -30,7 +30,17 @@ bool DatabasePage::validatePage()
|
||||
Q_ASSERT(importWizard);
|
||||
Q_ASSERT(!importWizard->database().isOpen());
|
||||
|
||||
importWizard->database() = m_ui->databaseWidget->createConnection();
|
||||
importWizard->database() = QSqlDatabase::addDatabase(m_ui->databaseWidget->driver());
|
||||
|
||||
if (importWizard->database().driverName() == "QSQLITE")
|
||||
importWizard->database().setDatabaseName(m_ui->databaseWidget->sqliteFilepath());
|
||||
else
|
||||
{
|
||||
importWizard->database().setHostName(m_ui->databaseWidget->mysqlHostname());
|
||||
importWizard->database().setUserName(m_ui->databaseWidget->mysqlUsername());
|
||||
importWizard->database().setPassword(m_ui->databaseWidget->mysqlPassword());
|
||||
importWizard->database().setDatabaseName(m_ui->databaseWidget->mysqlDatabase());
|
||||
}
|
||||
|
||||
if (!importWizard->database().open())
|
||||
{
|
||||
|
Reference in New Issue
Block a user