summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-09-18 15:10:21 +0200
committerYorhel <git@yorhel.nl>2009-09-18 15:10:21 +0200
commitb36adf6d49cde8135843e1b357dd5e016a69aa7f (patch)
treed1315ca434029bf40f857e0f01e32b3e6486e39d
parent74ee0a0a922219f16ab4873db80724bd59bb62ea (diff)
Renamed GeldTransactionModel + tiny fixups in Transaction
-rw-r--r--Geld.pro4
-rw-r--r--geld.cpp10
-rw-r--r--geldtransactionmodel.h14
-rw-r--r--transaction.cpp4
-rw-r--r--transactionmodel.cpp (renamed from geldtransactionmodel.cpp)8
-rw-r--r--transactionmodel.h14
6 files changed, 26 insertions, 28 deletions
diff --git a/Geld.pro b/Geld.pro
index 197b1ce..647281f 100644
--- a/Geld.pro
+++ b/Geld.pro
@@ -6,11 +6,11 @@ TARGET = Geld
TEMPLATE = app
SOURCES += main.cpp \
geld.cpp \
- geldtransactionmodel.cpp \
+ transactionmodel.cpp \
transaction.cpp \
contraaccount.cpp
HEADERS += geld.h \
- geldtransactionmodel.h \
+ transactionmodel.h \
transaction.h \
contraaccount.h
FORMS += geld.ui \
diff --git a/geld.cpp b/geld.cpp
index 5f6f087..4308814 100644
--- a/geld.cpp
+++ b/geld.cpp
@@ -5,7 +5,7 @@
#include <QtGlobal>
#include <QSqlQueryModel>
#include <QMessageBox>
-#include "geldtransactionmodel.h"
+#include "transactionmodel.h"
#include "transaction.h"
@@ -24,7 +24,7 @@ Geld::Geld(QWidget *parent)
ui->setupUi(this);
initDB(f);
- GeldTransactionModel *transmod = new GeldTransactionModel(ui->tableTransactions);
+ TransactionModel *transmod = new TransactionModel(ui->tableTransactions);
ui->tableTransactions->setModel(transmod);
ui->tableTransactions->setColumnHidden(0, true);
ui->tableTransactions->resizeColumnsToContents();
@@ -83,7 +83,7 @@ void Geld::closeDB()
void Geld::on_btnEditTransaction_clicked()
{
// this. is. soooooooo. ugly.
- GeldTransactionModel *mod = (GeldTransactionModel *) ui->tableTransactions->model();
+ TransactionModel *mod = (TransactionModel *) ui->tableTransactions->model();
QModelIndexList indexes = ui->tableTransactions->selectionModel()->selection().indexes();
if(indexes.count() != mod->columnCount())
return ui->statusBar->showMessage("Nothing selected.", 3000);
@@ -101,13 +101,13 @@ void Geld::on_btnAddTramsactopm_clicked()
Transaction t(this);
if(t.exec() == QDialog::Accepted) {
t.save();
- ((GeldTransactionModel *) ui->tableTransactions->model())->refresh();
+ ((TransactionModel *) ui->tableTransactions->model())->refresh();
}
}
void Geld::on_tableTransactions_doubleClicked(QModelIndex index)
{
- GeldTransactionModel *mod = (GeldTransactionModel *) ui->tableTransactions->model();
+ TransactionModel *mod = (TransactionModel *) ui->tableTransactions->model();
int id = mod->record(index.row()).value("id").toInt();
Transaction t(this);
t.load(id);
diff --git a/geldtransactionmodel.h b/geldtransactionmodel.h
deleted file mode 100644
index 081041d..0000000
--- a/geldtransactionmodel.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef GELDTRANSACTIONMODEL_H
-#define GELDTRANSACTIONMODEL_H
-
-#include <QSqlQueryModel>
-
-class GeldTransactionModel : public QSqlQueryModel
-{
-public:
- GeldTransactionModel(QObject * parent = 0);
- void refresh();
- QVariant data(const QModelIndex &index, int role) const;
-};
-
-#endif // GELDTRANSACTIONMODEL_H
diff --git a/transaction.cpp b/transaction.cpp
index 3367834..eea8f38 100644
--- a/transaction.cpp
+++ b/transaction.cpp
@@ -63,7 +63,7 @@ void Transaction::load(int id)
q.exec();
q.next();
m_ui->Date->setText(q.value(0).toString());
- m_ui->Amount->setText(QString("%1").arg(q.value(1).toDouble()/100));
+ m_ui->Amount->setText(QString("%1").arg(q.value(1).toDouble()/100, 4, 'f', 2));
m_ui->Currency->setCurrentIndex(m_ui->Currency->findText(q.value(2).toString()));
m_ui->Contra->setCurrentIndex(m_ui->Contra->findData(q.value(3)));
m_ui->Description->setPlainText(q.value(4).toString());
@@ -84,7 +84,6 @@ void Transaction::save(int id)
if(id)
q.addBindValue(id);
q.exec();
- // TODO: error handling?
}
void Transaction::on_Contra_currentIndexChanged(int index)
@@ -95,7 +94,6 @@ void Transaction::on_Contra_currentIndexChanged(int index)
ContraAccount c(this);
if(c.exec() == QDialog::Accepted) {
int id = c.save(0);
- qDebug() << "id = " << id;
populateContra();
m_ui->Contra->setCurrentIndex(m_ui->Contra->findData(id));
} else {
diff --git a/geldtransactionmodel.cpp b/transactionmodel.cpp
index e2b9501..59143e0 100644
--- a/geldtransactionmodel.cpp
+++ b/transactionmodel.cpp
@@ -1,16 +1,16 @@
-#include "geldtransactionmodel.h"
+#include "transactionmodel.h"
#include <QDebug>
#include <QStringList>
#include <QtSql>
-GeldTransactionModel::GeldTransactionModel(QObject *parent)
+TransactionModel::TransactionModel(QObject *parent)
: QSqlQueryModel(parent)
{
Q_UNUSED(parent);
refresh();
}
-void GeldTransactionModel::refresh() {
+void TransactionModel::refresh() {
setQuery(
"SELECT t.id, t.date, t.amount||' '||t.currency, c.name, t.description "
"FROM transactions t "
@@ -24,7 +24,7 @@ void GeldTransactionModel::refresh() {
setHeaderData(4, Qt::Horizontal, "Description");
}
-QVariant GeldTransactionModel::data(const QModelIndex &index, int role) const
+QVariant TransactionModel::data(const QModelIndex &index, int role) const
{
QVariant val = QSqlQueryModel::data(index, role);
if(role == Qt::DisplayRole && index.column() == 2) {
diff --git a/transactionmodel.h b/transactionmodel.h
new file mode 100644
index 0000000..72dfedb
--- /dev/null
+++ b/transactionmodel.h
@@ -0,0 +1,14 @@
+#ifndef TRANSACTIONMODEL_H
+#define TRANSACTIONMODEL_H
+
+#include <QSqlQueryModel>
+
+class TransactionModel : public QSqlQueryModel
+{
+public:
+ TransactionModel(QObject * parent = 0);
+ void refresh();
+ QVariant data(const QModelIndex &index, int role) const;
+};
+
+#endif // TRANSACTIONMODEL_H