Added ChecklistModel, ProgressModel, DatabaseWidget and FileselectionWidget
This commit is contained in:
@@ -6,35 +6,45 @@ find_package(Qt5Widgets CONFIG REQUIRED)
|
||||
find_package(Qt5LinguistTools CONFIG REQUIRED)
|
||||
|
||||
set(HEADERS
|
||||
canvaswidget.h
|
||||
dbguilib_global.h
|
||||
editorfactory.h
|
||||
ledindicator.h
|
||||
limitedspinbox.h
|
||||
matrix4x4widget.h
|
||||
quaternionwidget.h
|
||||
stringlistwidget.h
|
||||
urlwidget.h
|
||||
vector2dwidget.h
|
||||
vector3dwidget.h
|
||||
vector4dwidget.h
|
||||
models/checklistmodel.h
|
||||
models/progressmodel.h
|
||||
widgets/canvaswidget.h
|
||||
widgets/databasewidget.h
|
||||
widgets/fileselectionwidget.h
|
||||
widgets/ledindicator.h
|
||||
widgets/limitedspinbox.h
|
||||
widgets/matrix4x4widget.h
|
||||
widgets/quaternionwidget.h
|
||||
widgets/stringlistwidget.h
|
||||
widgets/urlwidget.h
|
||||
widgets/vector2dwidget.h
|
||||
widgets/vector3dwidget.h
|
||||
widgets/vector4dwidget.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
canvaswidget.cpp
|
||||
editorfactory.cpp
|
||||
ledindicator.cpp
|
||||
matrix4x4widget.cpp
|
||||
quaternionwidget.cpp
|
||||
stringlistwidget.cpp
|
||||
urlwidget.cpp
|
||||
vector2dwidget.cpp
|
||||
vector3dwidget.cpp
|
||||
vector4dwidget.cpp
|
||||
models/checklistmodel.cpp
|
||||
models/progressmodel.cpp
|
||||
widgets/canvaswidget.cpp
|
||||
widgets/databasewidget.cpp
|
||||
widgets/fileselectionwidget.cpp
|
||||
widgets/ledindicator.cpp
|
||||
widgets/matrix4x4widget.cpp
|
||||
widgets/quaternionwidget.cpp
|
||||
widgets/stringlistwidget.cpp
|
||||
widgets/urlwidget.cpp
|
||||
widgets/vector2dwidget.cpp
|
||||
widgets/vector3dwidget.cpp
|
||||
widgets/vector4dwidget.cpp
|
||||
)
|
||||
|
||||
set(FORMS
|
||||
qstringlistwidget.ui
|
||||
widgets/databasewidget.ui
|
||||
widgets/fileselectionwidget.ui
|
||||
widgets/qstringlistwidget.ui
|
||||
)
|
||||
|
||||
set(TRANSLATIONS
|
||||
|
@@ -12,14 +12,14 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "limitedspinbox.h"
|
||||
#include "stringlistwidget.h"
|
||||
#include "urlwidget.h"
|
||||
#include "matrix4x4widget.h"
|
||||
#include "vector2dwidget.h"
|
||||
#include "vector3dwidget.h"
|
||||
#include "vector4dwidget.h"
|
||||
#include "quaternionwidget.h"
|
||||
#include "widgets/limitedspinbox.h"
|
||||
#include "widgets/stringlistwidget.h"
|
||||
#include "widgets/urlwidget.h"
|
||||
#include "widgets/matrix4x4widget.h"
|
||||
#include "widgets/vector2dwidget.h"
|
||||
#include "widgets/vector3dwidget.h"
|
||||
#include "widgets/vector4dwidget.h"
|
||||
#include "widgets/quaternionwidget.h"
|
||||
|
||||
EditorFactory::EditorFactory() :
|
||||
QItemEditorFactory()
|
||||
|
182
models/checklistmodel.cpp
Normal file
182
models/checklistmodel.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
#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;
|
||||
}
|
42
models/checklistmodel.h
Normal file
42
models/checklistmodel.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#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;
|
||||
};
|
148
models/progressmodel.cpp
Normal file
148
models/progressmodel.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#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();
|
||||
}
|
59
models/progressmodel.h
Normal file
59
models/progressmodel.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#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,6 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="de_DE">
|
||||
<context>
|
||||
<name>DatabaseWidget</name>
|
||||
<message>
|
||||
<source>Form</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Hostname:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Username:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Password:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Database:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SQLite</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MySQL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>FileSelectionWidget</name>
|
||||
<message>
|
||||
<source>Form</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Select...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QStringListWidget</name>
|
||||
<message>
|
||||
|
@@ -1,6 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="en_US">
|
||||
<context>
|
||||
<name>DatabaseWidget</name>
|
||||
<message>
|
||||
<source>Form</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Hostname:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Username:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Password:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><b>Database:</b></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SQLite</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>MySQL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>FileSelectionWidget</name>
|
||||
<message>
|
||||
<source>Form</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Select...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QStringListWidget</name>
|
||||
<message>
|
||||
|
88
widgets/databasewidget.cpp
Normal file
88
widgets/databasewidget.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#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);
|
||||
}
|
37
widgets/databasewidget.h
Normal file
37
widgets/databasewidget.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#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);
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::DatabaseWidget> m_ui;
|
||||
};
|
167
widgets/databasewidget.ui
Normal file
167
widgets/databasewidget.ui
Normal file
@@ -0,0 +1,167 @@
|
||||
<?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>
|
75
widgets/fileselectionwidget.cpp
Normal file
75
widgets/fileselectionwidget.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#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);
|
||||
}
|
39
widgets/fileselectionwidget.h
Normal file
39
widgets/fileselectionwidget.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#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;
|
||||
};
|
43
widgets/fileselectionwidget.ui
Normal file
43
widgets/fileselectionwidget.ui
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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>
|
Reference in New Issue
Block a user