tabbed UI
This commit is contained in:
parent
a5e6b72aca
commit
dcdcb6f3dd
|
@ -1,10 +1,10 @@
|
||||||
#include "EditWindow.h"
|
#include "EditWindow.h"
|
||||||
|
#include "ui_EditWindow.h"
|
||||||
|
|
||||||
EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
|
EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
/* connect query with common global database */
|
QSqlQuery query;
|
||||||
query = QSqlQuery(db);
|
|
||||||
|
|
||||||
model = new QSqlRelationalTableModel(this);
|
model = new QSqlRelationalTableModel(this);
|
||||||
model->setTable("socio");
|
model->setTable("socio");
|
||||||
|
@ -21,7 +21,7 @@ EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(n
|
||||||
|
|
||||||
if (! model->select()) {
|
if (! model->select()) {
|
||||||
qDebug() << fullQuery(query);
|
qDebug() << fullQuery(query);
|
||||||
qDebug() << db.lastError().text();
|
qDebug() << query.lastError().text();
|
||||||
Ui::status(Ui::ERROR, "query error");
|
Ui::status(Ui::ERROR, "query error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef EDITWINDOW_H
|
#pragma once
|
||||||
#define EDITWINDOW_H
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
#include "EditWindow.h"
|
#include "EditWindow.h"
|
||||||
#include "fullQuery.h"
|
#include "fullQuery.h"
|
||||||
#include "status.h"
|
#include "status.h"
|
||||||
#include "ui_EditWindow.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class EditWindow;
|
class EditWindow;
|
||||||
|
@ -37,6 +35,3 @@ private:
|
||||||
|
|
||||||
Ui::EditWindow *ui;
|
Ui::EditWindow *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -1,81 +1,15 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "ui_MainWindow.h"
|
||||||
|
|
||||||
MainWindow* mw;
|
QStatusBar* statusBar = nullptr;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::connectDatabase(void) {
|
|
||||||
/* retrieve settings for this application, group database */
|
|
||||||
QSettings settings("it.linux.golem", "argento");
|
|
||||||
settings.beginGroup("database");
|
|
||||||
|
|
||||||
/* open database and attach query */
|
|
||||||
db = QSqlDatabase::addDatabase("QMYSQL"); /* QMYSQL <-- database driver */
|
|
||||||
db.setHostName(settings.value("hostname").toString());
|
|
||||||
db.setDatabaseName(settings.value("database").toString());
|
|
||||||
db.setUserName(settings.value("username").toString());
|
|
||||||
db.setPassword(settings.value("password").toString());
|
|
||||||
|
|
||||||
status(Ui::INFO, QString("Connecting to %1...").arg(settings.value("hostname").toString()));
|
|
||||||
|
|
||||||
if (! db.open())
|
|
||||||
status(Ui::ERROR, db.lastError().text());
|
|
||||||
else
|
|
||||||
status(Ui::INFO, QString("Connected to %1").arg(settings.value("hostname").toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_buttonCerca_clicked() {
|
|
||||||
if (!db.open()) connectDatabase();
|
|
||||||
|
|
||||||
QSqlQuery query;
|
|
||||||
query.prepare("SELECT id, nome, cognome FROM socio WHERE LOWER(nome) LIKE LOWER(:nome) AND LOWER(cognome) LIKE LOWER(:cognome)");
|
|
||||||
query.bindValue( ":nome", QString("%%1%").arg(ui->lineNome->text()) );
|
|
||||||
query.bindValue( ":cognome", QString("%%1%").arg(ui->lineCognome->text()) );
|
|
||||||
|
|
||||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
|
||||||
if ( query.size() == 0) { status(Ui::INFO, "no results found"); return; }
|
|
||||||
|
|
||||||
model.setQuery(query);
|
|
||||||
|
|
||||||
status(Ui::INFO, QString("%1 results found").arg(query.size()));
|
|
||||||
|
|
||||||
ui->tableSoci->setModel(&model);
|
|
||||||
/* the signal is automagically added by some obscure qt build system, provided the function is named in a standard way */
|
|
||||||
//QObject::connect(tableSoci, SIGNAL(clicked(const QModelIndex&)), this, SLOT(on_tableSoci_clicked(const QModelIndex&)));
|
|
||||||
ui->tableSoci->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_buttonNuovo_clicked() {
|
|
||||||
if (! db.open()) connectDatabase();
|
|
||||||
|
|
||||||
QSqlQuery query;
|
|
||||||
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
|
|
||||||
query.bindValue(":nome", ui->lineNome->text());
|
|
||||||
query.bindValue(":cognome", ui->lineCognome->text());
|
|
||||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
|
||||||
|
|
||||||
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
|
|
||||||
|
|
||||||
EditWindow*w = new EditWindow(query.lastInsertId().toInt(), this);
|
|
||||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
w->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_tableSoci_clicked(const QModelIndex& index) {
|
|
||||||
if (index.isValid()) {
|
|
||||||
/* extracts id socio from first column of table view */
|
|
||||||
int id = index.model()->data(index.sibling(index.row(), 0)).toInt();
|
|
||||||
if (id != 0) { /* if click is not on other fields than id... */
|
|
||||||
EditWindow* w = new EditWindow(id, this);
|
|
||||||
w->setAttribute(Qt::WA_DeleteOnClose); /* delete window at the end */
|
|
||||||
w->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
QSqlDatabase db = QSqlDatabase::database();
|
||||||
|
if (db.isOpen()) {
|
||||||
|
status(Ui::INFO, QString("Connected to %1").arg(db.hostName()));
|
||||||
|
} else {
|
||||||
|
status(Ui::ERROR, "Cannot connect to database: " + db.lastError().text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#ifndef MAINWINDOW_H
|
#pragma once
|
||||||
#define MAINWINDOW_H
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
|
|
||||||
|
#include "SociListTab.h"
|
||||||
#include "EditWindow.h"
|
#include "EditWindow.h"
|
||||||
#include "MainWindow.h"
|
|
||||||
#include "ui_MainWindow.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
@ -21,20 +19,11 @@ private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QSqlQueryModel model;
|
QSqlQueryModel model;
|
||||||
|
|
||||||
void connectDatabase(void);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
|
||||||
|
|
||||||
//void setStatus(Ui::StatusType type, QString message);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_buttonCerca_clicked();
|
|
||||||
void on_buttonNuovo_clicked();
|
|
||||||
void on_tableSoci_clicked(const QModelIndex& index);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MainWindow* mw;
|
extern QStatusBar* statusBar;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -16,48 +16,30 @@
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<item row="0" column="0">
|
<property name="currentIndex">
|
||||||
<widget class="QLabel" name="label">
|
<number>0</number>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>Nome</string>
|
<widget class="QWidget" name="tab">
|
||||||
</property>
|
<attribute name="title">
|
||||||
</widget>
|
<string>Soci</string>
|
||||||
</item>
|
</attribute>
|
||||||
<item row="0" column="1">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<widget class="QLabel" name="label_2">
|
<item row="0" column="0">
|
||||||
<property name="text">
|
<widget class="SociListTab" name="widget" native="true"/>
|
||||||
<string>Cognome</string>
|
</item>
|
||||||
</property>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
<widget class="QWidget" name="tab_2">
|
||||||
<item row="1" column="0">
|
<attribute name="title">
|
||||||
<widget class="QLineEdit" name="lineNome"/>
|
<string>Rinnovi</string>
|
||||||
</item>
|
</attribute>
|
||||||
<item row="1" column="1">
|
</widget>
|
||||||
<widget class="QLineEdit" name="lineCognome"/>
|
</widget>
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QPushButton" name="buttonCerca">
|
|
||||||
<property name="text">
|
|
||||||
<string>Cerca</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="3">
|
|
||||||
<widget class="QPushButton" name="buttonNuovo">
|
|
||||||
<property name="text">
|
|
||||||
<string>Nuovo</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="4">
|
|
||||||
<widget class="QTableView" name="tableSoci"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -75,13 +57,20 @@
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuwhat_s_this"/>
|
<addaction name="menuwhat_s_this"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusBar"/>
|
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Exit</string>
|
<string>Exit</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>SociListTab</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>SociListTab.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
#include "SociListTab.h"
|
||||||
|
#include "ui_SociListTab.h"
|
||||||
|
|
||||||
|
SociListTab::SociListTab(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::SociListTab)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
void SociListTab::connectDatabase(void) {
|
||||||
|
// retrieve settings for this application, group database
|
||||||
|
QSettings settings("it.linux.golem", "argento");
|
||||||
|
settings.beginGroup("database");
|
||||||
|
|
||||||
|
// open database and attach query
|
||||||
|
db = QSqlDatabase::addDatabase("QMYSQL"); // QMYSQL <-- database driver
|
||||||
|
db.setHostName(settings.value("hostname").toString());
|
||||||
|
db.setDatabaseName(settings.value("database").toString());
|
||||||
|
db.setUserName(settings.value("username").toString());
|
||||||
|
db.setPassword(settings.value("password").toString());
|
||||||
|
|
||||||
|
status(Ui::INFO, QString("Connecting to %1...").arg(settings.value("hostname").toString()));
|
||||||
|
|
||||||
|
if (! db.open())
|
||||||
|
status(Ui::ERROR, db.lastError().text());
|
||||||
|
else
|
||||||
|
status(Ui::INFO, QString("Connected to %1").arg(settings.value("hostname").toString()));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SociListTab::on_buttonCerca_clicked() {
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("SELECT id, nome, cognome FROM socio WHERE LOWER(nome) LIKE LOWER(:nome) AND LOWER(cognome) LIKE LOWER(:cognome)");
|
||||||
|
query.bindValue( ":nome", QString("%%1%").arg(ui->lineNome->text()) );
|
||||||
|
query.bindValue( ":cognome", QString("%%1%").arg(ui->lineCognome->text()) );
|
||||||
|
|
||||||
|
if (! query.exec()) {
|
||||||
|
qDebug() << "query not executed: " << query.lastError().text();
|
||||||
|
status(Ui::ERROR, fullQuery(query));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( query.size() == 0) {
|
||||||
|
qDebug() << "size == 0";
|
||||||
|
status(Ui::INFO, "no results found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.setQuery(query);
|
||||||
|
|
||||||
|
status(Ui::INFO, QString("%1 results found").arg(query.size()));
|
||||||
|
|
||||||
|
ui->tableSoci->setModel(&model);
|
||||||
|
ui->tableSoci->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SociListTab::on_buttonNuovo_clicked() {
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
|
||||||
|
query.bindValue(":nome", ui->lineNome->text());
|
||||||
|
query.bindValue(":cognome", ui->lineCognome->text());
|
||||||
|
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||||
|
|
||||||
|
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||||
|
|
||||||
|
EditWindow*w = new EditWindow(query.lastInsertId().toInt(), this);
|
||||||
|
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
w->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SociListTab::on_tableSoci_clicked(const QModelIndex& index) {
|
||||||
|
if (index.isValid()) {
|
||||||
|
/* extracts id socio from first column of table view */
|
||||||
|
int id = index.model()->data(index.sibling(index.row(), 0)).toInt();
|
||||||
|
if (id != 0) { /* if click is not on other fields than id... */
|
||||||
|
EditWindow* w = new EditWindow(id, this);
|
||||||
|
w->setAttribute(Qt::WA_DeleteOnClose); /* delete window at the end */
|
||||||
|
w->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
#include <QSqlQueryModel>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QTableWidgetItem>
|
||||||
|
|
||||||
|
#include "EditWindow.h"
|
||||||
|
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class SociListTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SociListTab : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::SociListTab *ui;
|
||||||
|
QSqlQueryModel model;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SociListTab(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_buttonCerca_clicked();
|
||||||
|
void on_buttonNuovo_clicked();
|
||||||
|
void on_tableSoci_clicked(const QModelIndex& index);
|
||||||
|
};
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SociListTab</class>
|
||||||
|
<widget class="QWidget" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>623</width>
|
||||||
|
<height>421</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Gestionale Argento</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cognome</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLineEdit" name="lineNome"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QPushButton" name="buttonCerca">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cerca</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="3">
|
||||||
|
<widget class="QPushButton" name="buttonNuovo">
|
||||||
|
<property name="text">
|
||||||
|
<string>Nuovo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="lineCognome"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Nome</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="4">
|
||||||
|
<widget class="QTableView" name="tableSoci"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
<action name="actionExit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -24,25 +24,26 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
db.cpp \
|
|
||||||
EditWindow.cpp \
|
EditWindow.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
MainWindow.cpp \
|
MainWindow.cpp \
|
||||||
status.cpp \
|
status.cpp \
|
||||||
fullQuery.cpp
|
fullQuery.cpp \
|
||||||
|
SociListTab.cpp
|
||||||
|
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
db.h \
|
|
||||||
EditWindow.h \
|
EditWindow.h \
|
||||||
MainWindow.h \
|
MainWindow.h \
|
||||||
status.h \
|
status.h \
|
||||||
fullQuery.h
|
fullQuery.h \
|
||||||
|
SociListTab.h
|
||||||
|
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
MainWindow.ui \
|
MainWindow.ui \
|
||||||
EditWindow.ui
|
EditWindow.ui \
|
||||||
|
SociListTab.ui
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#include "db.h"
|
|
||||||
|
|
||||||
QSqlDatabase db;
|
|
12
argento/db.h
12
argento/db.h
|
@ -1,12 +0,0 @@
|
||||||
#ifndef DB_H
|
|
||||||
#define DB_H
|
|
||||||
|
|
||||||
#include <QSqlDatabase>
|
|
||||||
#include <QSqlError>
|
|
||||||
#include <QSqlQuery>
|
|
||||||
#include <QSqlRecord>
|
|
||||||
|
|
||||||
extern QSqlDatabase db;
|
|
||||||
extern QSqlQuery query;
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -10,12 +10,22 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
mw = new MainWindow;
|
/* retrieve settings for this application, group database */
|
||||||
mw->show();
|
QSettings settings("it.linux.golem", "argento");
|
||||||
|
settings.beginGroup("database");
|
||||||
|
|
||||||
int ret = a.exec();
|
/* open database and attach query */
|
||||||
|
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); /* QMYSQL <-- database driver */
|
||||||
|
db.setHostName(settings.value("hostname").toString());
|
||||||
|
db.setDatabaseName(settings.value("database").toString());
|
||||||
|
db.setUserName(settings.value("username").toString());
|
||||||
|
db.setPassword(settings.value("password").toString());
|
||||||
|
|
||||||
delete mw;
|
db.open();
|
||||||
|
|
||||||
return ret;
|
MainWindow window;
|
||||||
|
statusBar = window.statusBar();
|
||||||
|
window.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
void status(StatusType type, QString message) {
|
void status(StatusType type, QString message) {
|
||||||
//QStatusBar* statusBar = mw->findChild<QStatusBar*>("statusBar");
|
//QStatusBar* statusBar = mw->statusBar();
|
||||||
QStatusBar* statusBar = mw->statusBar();
|
|
||||||
QString prefix;
|
QString prefix;
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef STATUS_H
|
#pragma once
|
||||||
#define STATUS_H
|
|
||||||
|
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -19,4 +18,3 @@ namespace Ui {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue