diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cb85258 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/dialogs/opendialog.cpp b/dialogs/opendialog.cpp index b55f26c..7da3e85 100644 --- a/dialogs/opendialog.cpp +++ b/dialogs/opendialog.cpp @@ -25,7 +25,17 @@ std::unique_ptr &OpenDialog::project() void OpenDialog::submit() { auto project = std::make_unique(); - 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()) { diff --git a/gzipdevice.cpp b/gzipdevice.cpp deleted file mode 100644 index 5f0bcf8..0000000 --- a/gzipdevice.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "gzipdevice.h" - -#include - -#include - -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(m_readBuffer); - strm.avail_in = m_file.read(m_readBuffer, m_readBufferSize); - } - - strm.next_out = reinterpret_cast(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; -} diff --git a/gzipdevice.h b/gzipdevice.h deleted file mode 100644 index 05780c1..0000000 --- a/gzipdevice.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#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; -}; diff --git a/loganalyzer.pro b/loganalyzer.pro deleted file mode 100644 index 26a422b..0000000 --- a/loganalyzer.pro +++ /dev/null @@ -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 diff --git a/resources.qrc b/loganalyzer_resources.qrc similarity index 100% rename from resources.qrc rename to loganalyzer_resources.qrc diff --git a/models/checklistmodel.cpp b/models/checklistmodel.cpp deleted file mode 100644 index 7b0633c..0000000 --- a/models/checklistmodel.cpp +++ /dev/null @@ -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 &items, QObject *parent) : - QAbstractListModel(parent), - m_items(items) -{ -} - -const QList &ChecklistModel::items() const -{ - return m_items; -} - -void ChecklistModel::setItems(const QList &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::enabledItems() const -{ - QList items; - - for (const auto &item : m_items) - if (item.checked) - items.append(item); - - return items; -} - -QList ChecklistModel::disabledItems() const -{ - QList 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; -} diff --git a/models/checklistmodel.h b/models/checklistmodel.h deleted file mode 100644 index 6a1fd2b..0000000 --- a/models/checklistmodel.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include - -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 &strings, QObject *parent = nullptr); - - const QList &items() const; - void setItems(const QList &items); - void setItems(const QStringList &items); - - QStringList itemTexts() const; - QVariantList itemDatas() const; - QList enabledItems() const; - QList 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 m_items; -}; diff --git a/models/progressmodel.cpp b/models/progressmodel.cpp deleted file mode 100644 index 80d0d34..0000000 --- a/models/progressmodel.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "progressmodel.h" - -#include - -#include - -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 &items, QObject *parent) : - QAbstractListModel(parent), - m_items(items) -{ - connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged); - - if (anyLoading()) - m_movieLoading.start(); -} - -const QVector &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 &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(); -} diff --git a/models/progressmodel.h b/models/progressmodel.h deleted file mode 100644 index b472011..0000000 --- a/models/progressmodel.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include -#include - -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 &items, QObject *parent = nullptr); - - const QVector &items() const; - void setItems(const QStringList &items); - void setItems(const QVector &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 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" }; -}; diff --git a/widgets/databasewidget.cpp b/widgets/databasewidget.cpp deleted file mode 100644 index 92da338..0000000 --- a/widgets/databasewidget.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "databasewidget.h" -#include "ui_databasewidget.h" - -DatabaseWidget::DatabaseWidget(QWidget *parent) : - QWidget(parent), - m_ui(std::make_unique()) -{ - 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; -} diff --git a/widgets/databasewidget.h b/widgets/databasewidget.h deleted file mode 100644 index 59b7dd5..0000000 --- a/widgets/databasewidget.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -#include - -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 m_ui; -}; diff --git a/widgets/databasewidget.ui b/widgets/databasewidget.ui deleted file mode 100644 index c7cb6e6..0000000 --- a/widgets/databasewidget.ui +++ /dev/null @@ -1,167 +0,0 @@ - - - DatabaseWidget - - - - 0 - 0 - 400 - 175 - - - - Form - - - - - - - - - 1 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - - <b>Hostname:</b> - - - lineEditHostname - - - - - - - <b>Username:</b> - - - lineEditUsername - - - - - - - <b>Password:</b> - - - lineEditPassword - - - - - - - <b>Database:</b> - - - lineEditDatabase - - - - - - - QLineEdit::Password - - - - - - - - - - - - - - - FileSelectionWidget - QWidget -
widgets/fileselectionwidget.h
- 1 -
-
- - comboBox - lineEditHostname - lineEditUsername - lineEditPassword - lineEditDatabase - - - - - comboBox - currentIndexChanged(int) - stackedWidget - setCurrentIndex(int) - - - 199 - 20 - - - 199 - 101 - - - - -
diff --git a/widgets/fileselectionwidget.cpp b/widgets/fileselectionwidget.cpp deleted file mode 100644 index e67f6aa..0000000 --- a/widgets/fileselectionwidget.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "fileselectionwidget.h" -#include "ui_fileselectionwidget.h" - -#include - -FileSelectionWidget::FileSelectionWidget(QWidget *parent) : - QWidget(parent), - m_ui(std::make_unique()), - 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()), - 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()), - 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); -} diff --git a/widgets/fileselectionwidget.h b/widgets/fileselectionwidget.h deleted file mode 100644 index 2f63149..0000000 --- a/widgets/fileselectionwidget.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include - -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 m_ui; - Mode m_mode; -}; diff --git a/widgets/fileselectionwidget.ui b/widgets/fileselectionwidget.ui deleted file mode 100644 index e2abf64..0000000 --- a/widgets/fileselectionwidget.ui +++ /dev/null @@ -1,43 +0,0 @@ - - - FileSelectionWidget - - - - 0 - 0 - 400 - 41 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Select... - - - - - - - - diff --git a/wizard/databasepage.cpp b/wizard/databasepage.cpp index 162cacd..69d888b 100644 --- a/wizard/databasepage.cpp +++ b/wizard/databasepage.cpp @@ -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()) {