Commit 5c3d6a24 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Add ability to add new money accounts

parent 9616397b
......@@ -322,11 +322,7 @@ MainWindow::MainWindow(QWidget *parent) :
setMoneyAccountValues();
QSqlQuery accQuery("SELECT id, name FROM money");
while (accQuery.next()) {
ui->accTransferFrom->addItem(accQuery.value(1).toString(), accQuery.value(0));
ui->accTransferTo->addItem(accQuery.value(1).toString(), accQuery.value(0));
}
setAccTransferCombo();
}
MainWindow::~MainWindow()
......@@ -340,6 +336,18 @@ void MainWindow::updateMoneyString()
setMoneyAccountValues();
}
void MainWindow::setAccTransferCombo() {
ui->accTransferFrom->clear();
ui->accTransferTo->clear();
QSqlQuery accQuery("SELECT id, name FROM money");
while (accQuery.next()) {
ui->accTransferFrom->addItem(accQuery.value(1).toString(), accQuery.value(0));
ui->accTransferTo->addItem(accQuery.value(1).toString(), accQuery.value(0));
}
}
void MainWindow::setMoneyAccountValues() {
QSqlTableModel* accModel = (QSqlTableModel*) ui->accTreeView->model();
......@@ -868,3 +876,32 @@ void MainWindow::on_accTransferSubmit_clicked()
updateMoneyString();
}
void MainWindow::on_accUpdateBtn_clicked()
{
setMoneyAccountValues();
}
void MainWindow::on_accNewAccBtn_clicked()
{
QString name = ui->accNewAccText->text();
if (name.isEmpty()) return;
QSqlQuery query;
query.prepare("INSERT INTO money (name) VALUES (:name)");
query.bindValue(":name", name);
if (!query.exec()) {
qDebug() << query.lastError();
if (query.lastError().text().contains("UNIQUE")) {
QMessageBox::warning(this, "Add failed",
"Account with that name probably already exitst. "
"It's either that, or that SQLite have bad error messages");
return;
}
}
ui->accNewAccText->setText("");
setMoneyAccountValues();
setAccTransferCombo();
}
......@@ -81,6 +81,10 @@ private slots:
void on_accTransferSubmit_clicked();
void on_accUpdateBtn_clicked();
void on_accNewAccBtn_clicked();
private:
Ui::MainWindow *ui;
QSqlTableModel* model;
......@@ -105,6 +109,7 @@ private:
QVariant get_projected_stock_value();
QVariant get_acquistion_stock_value();
void setStockValues();
void setAccTransferCombo();
void open_till();
};
......
......@@ -764,12 +764,30 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="accNewAccBtn">
<widget class="QPushButton" name="accUpdateBtn">
<property name="text">
<string>Lägg till konto</string>
<string>Uppdatera</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLineEdit" name="accNewAccText">
<property name="placeholderText">
<string>Kontonamn</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="accNewAccBtn">
<property name="text">
<string>Lägg till konto</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="3">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment