Imported existing sources
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#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;
|
||||
};
|
||||
@@ -0,0 +1,124 @@
|
||||
<?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>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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">
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelUsername">
|
||||
<property name="text">
|
||||
<string><b>Username:</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelPassword">
|
||||
<property name="text">
|
||||
<string><b>Password:</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelDatabase">
|
||||
<property name="text">
|
||||
<string><b>Database:</b></string>
|
||||
</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>
|
||||
<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>
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class FileSelectionWidget; }
|
||||
|
||||
class FileSelectionWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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;
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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">
|
||||
<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