The crud now support inserting new rows

This commit is contained in:
eelke 2018-02-18 08:37:59 +01:00
parent c51bd7594d
commit 09d5c1e41a
2 changed files with 154 additions and 61 deletions

View file

@ -197,13 +197,25 @@ private:
bool callLoadData = false;
std::shared_ptr<Pgsql::Result> m_roData;
/// \brief Total number of rows to show.
///
/// The first n rows are the rows in m_roData.
/// While a row is being edited the modifications are in the PendingRowList
/// When the edits have been submitted the new values are put in the ModifiedRowList
///
/// The last row is for creating new rows. There is no data for this row or it is
/// in the PendingRowList. As soon as the row has been inserted a new last empty row
/// will be created by increasing this variable. And the newly stored row will be in
/// the modified list.
///
int m_rowCount = 0;
PendingRowList m_pendingRowList;
/** Maintains a list of all modified rows.
*
* The key values are the indexes of the row before any rows were deleted.
*/
/// \brief Maintains a list of all modified rows.
///
/// The key values are the indexes of the row before any rows were deleted.
///
ModifiedRowList m_modifiedRowList;
using RedirectVec = std::vector<int>;
@ -236,13 +248,17 @@ private:
/// This function should not be called when there is no primarykey. (Editing should be disabled anyway in that case)
///
/// \param row Actual result row not intermeddiat model row
/// \return
/// \return The values of the primary key column. If this is a new row it will return an empty list
///
PKeyValues getPKeyForRow(int row) const;
bool savePendingChanges();
std::tuple<QString, Pgsql::Params> createUpdateQuery(const PKeyValues &pkey_values, const PendingRow &pending_row);
std::tuple<QString, Pgsql::Params> createInsertQuery(const PendingRow &pending_row);
std::tuple<bool, ModifiedRow> updateRow(const PendingRow &pending_row);
void appendNewRow();
private slots:
void connectionStateChanged(ASyncDBConnection::State state);