CrudTab uses new PgLabItemDelegate, no need anymore for CrudModel to inherit BaseTableModel.

This commit is contained in:
eelke 2018-01-15 13:30:30 +01:00
parent 208883462c
commit a543ccb021
3 changed files with 60 additions and 14 deletions

View file

@ -1,11 +1,12 @@
#ifndef CRUDMODEL_H
#define CRUDMODEL_H
#include "BaseTableModel.h"
#include <QAbstractTableModel>
#include "ASyncDBConnection.h"
#include "PgClass.h"
#include "PgConstraint.h"
#include "Pgsql_Connection.h"
#include <map>
#include <memory>
#include <vector>
#include <boost/optional.hpp>
@ -32,7 +33,7 @@ class ASyncWindow;
* std::string has short string optimization so this probably means
* that a two dimensional array of std::string objects could actually be quite efficient!
*/
class CrudModel: public BaseTableModel {
class CrudModel: public QAbstractTableModel {
Q_OBJECT
public:
explicit CrudModel(ASyncWindow *async_win);
@ -50,9 +51,6 @@ public:
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual Qt::ItemFlags flags(const QModelIndex &) const override;
protected:
virtual Oid getType(int column) const override;
virtual QVariant getData(const QModelIndex &index) const override;
private:
ASyncWindow * m_asyncWindow;
@ -77,6 +75,52 @@ private:
// std::shared_ptr<RowList> resultToRowList(std::shared_ptr<Pgsql::Result> result);
using Value = boost::optional<std::string>;
/** Remembers the values that have been applies to a row after the original result was retrieved.
*/
class ModifiedRow {
public:
private:
std::vector<Value> m_values;
};
using ModifiedRowList = std::map<int, ModifiedRow>;
/** Manages the changes for the current row
*
*/
class PendingChanges {
public:
private:
int m_currentRow;
std::vector<std::string> m_currentPKeyValues; ///< The values to use for updating the row, for new rows this list is empty
std::map<int16_t, Value> m_values; ///< values that need to be applied
};
using DeletedList = std::vector<int>; // These are the original indexes before there were any modifications
PendingChanges m_pendingChanges;
/** Maintains a list of all modified rows.
*
* The key values are the indexes of the row before any rows were deleted.
*/
ModifiedRowList m_modifiedRowList;
// Alternative, vector of rows
class Row {
public:
int resultRow; ///< row index in original result, -1 for new rows
std::vector<Value> currentValues; ///
};
QVariant getData(const QModelIndex &index) const;
Oid getType(int column) const;
private slots:
void connectionStateChanged(ASyncDBConnection::State state);