# HG changeset patch # User Matti Hamalainen # Date 1499151218 -10800 # Node ID 62e570222f66b3800d1b9d75887885e31f4b3cc4 # Parent bb17f6714fa4023a1e919bf904f8cca4126b7deb Return inserted person ID from addPerson() (or negative value in case of errors.) diff -r bb17f6714fa4 -r 62e570222f66 src/main.cpp --- 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; } diff -r bb17f6714fa4 -r 62e570222f66 src/main.h --- 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();