Mercurial > hg > syntilista
changeset 109:62e570222f66
Return inserted person ID from addPerson() (or negative value in case of errors.)
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 04 Jul 2017 09:53:38 +0300 |
parents | bb17f6714fa4 |
children | 7a3e9d4c9b71 |
files | src/main.cpp src/main.h |
diffstat | 2 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.cpp Mon Jul 03 11:55:59 2017 +0300 +++ b/src/main.cpp Tue Jul 04 09:53:38 2017 +0300 @@ -1084,7 +1084,7 @@ } -int PersonSQLModel::addPerson(const PersonInfo &info) +qint64 PersonSQLModel::addPerson(const PersonInfo &info) { // beginInsertRows(QModelIndex(), rowCount(), rowCount()); @@ -1102,9 +1102,11 @@ QSqlDatabase::database().commit(); + QVariant idp = np.lastInsertId(); + // endInsertRows(); updateModel(); - return 0; + return idp.isValid() ? idp.toInt() : -2; }
--- a/src/main.h Mon Jul 03 11:55:59 2017 +0300 +++ b/src/main.h Tue Jul 04 09:53:38 2017 +0300 @@ -68,7 +68,7 @@ QVariant data(const QModelIndex &item, int role) const Q_DECL_OVERRIDE; int updatePerson(const PersonInfo &person); - int addPerson(const PersonInfo &person); + qint64 addPerson(const PersonInfo &person); int deletePerson(qint64 id); void updateModel(); }; @@ -120,6 +120,9 @@ PersonSQLModel *model_People; +public slots: + void focusDebtEdit(); + private slots: void on_button_AddPerson_clicked(); void on_button_EditPerson_clicked(); @@ -139,7 +142,6 @@ void selectedPersonChanged(const QModelIndex &, const QModelIndex &); - void focusDebtEdit(); void selectRowPrev(); void selectRowNext();