fix: Updates based on comments

This commit is contained in:
Alex Jbanca 2023-12-14 00:21:33 +02:00 committed by Alex Jbanca
parent 6da897e733
commit 56f194c96c
4 changed files with 1171 additions and 480 deletions

View File

@ -74,7 +74,7 @@ Item {
RowLayout{
Button {
text: "Insert"
text: "Insert at"
onClicked: {
listModel.insert(parseInt(insertIndex.text),{
name: "Item " + (listModel.count + 1),
@ -84,21 +84,21 @@ Item {
}
TextField {
id: insertIndex
text: "Insert at"
text: "0"
cursorVisible: false
inputMethodHints: Qt.ImhDigitsOnly
}
}
RowLayout{
Button {
text: "Remove"
text: "Remove at"
onClicked: {
listModel.remove(parseInt(removeIndex.text), 1)
}
}
TextField {
id: removeIndex
text: "Remove from"
text: "0"
cursorVisible: false
inputMethodHints: Qt.ImhDigitsOnly
}
@ -146,34 +146,42 @@ Item {
RowLayout{
Button {
text: "Insert"
text: "Insert at"
onClicked: {
if(writableProxyModel.insert(parseInt(insertWritableIndex.text)))
{
let item = writableProxyModel.get(parseInt(insertWritableIndex.text))
item.name = "New " + (listView.count + 1)
item.key = listView.count + 1
writableProxyModel.set(parseInt(insertWritableIndex.text), item)
}
writableProxyModel.insert(parseInt(insertWritableIndex.text), {
name: "Item " + (writableProxyModel.rowCount() + 1),
key: writableProxyModel.rowCount() + 1
})
}
}
TextField {
id: insertWritableIndex
text: "Insert at"
text: "0"
cursorVisible: false
inputMethodHints: Qt.ImhDigitsOnly
}
}
RowLayout{
Button {
text: "Remove"
text: "Append"
onClicked: {
writableProxyModel.append({
name: "Item " + (writableProxyModel.rowCount() + 1),
key: writableProxyModel.rowCount() + 1
})
}
}
}
RowLayout{
Button {
text: "Remove from"
onClicked: {
writableProxyModel.remove(parseInt(removeWritableIndex.text))
}
}
TextField {
id: removeWritableIndex
text: "Remove from"
text: "0"
cursorVisible: false
inputMethodHints: Qt.ImhDigitsOnly
}

View File

@ -32,7 +32,8 @@ public:
~WritableProxyModel();
Q_INVOKABLE QVariantMap toVariantMap() const;
Q_INVOKABLE bool insert(int at);
Q_INVOKABLE bool insert(int at, const QVariantMap& data = {});
Q_INVOKABLE bool append(const QVariantMap& data = {});
Q_INVOKABLE bool remove(int at);
//Returns a VariantMap of the data at the given index
//The map contains the role names as keys and the data as values
@ -46,50 +47,44 @@ public:
//QAbstractProxyModel overrides
void setSourceModel(QAbstractItemModel* sourceModel) override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QMap<int, QVariant> itemData(const QModelIndex& index) const override;
bool setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
QModelIndex parent(const QModelIndex &child) const override;
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex sibling(int row, int column, const QModelIndex& idx) const override;
QModelIndex parent(const QModelIndex& child) const override;
QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
void revert() override;
// TODO: implement these
// bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
// bool submit() override;
signals:
void dirtyChanged();
private:
void setDirty(bool flag);
void handleSourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
void handleRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void handleRowsInserted(const QModelIndex &parent, int first, int last);
void handleRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void handleRowsRemoved(const QModelIndex &parent, int first, int last);
void handleModelAboutToBeReset();
void handleModelReset();
void handleLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint);
void handleLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint);
void handleRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow);
bool m_dirty{false};
void onSourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
void onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end);
void onRowsInserted(const QModelIndex& parent, int first, int last);
void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
void onRowsRemoved(const QModelIndex& parent, int first, int last);
void onModelAboutToBeReset();
void onModelReset();
void onLayoutAboutToBeChanged(const QList<QPersistentModelIndex>& sourceParents, QAbstractItemModel::LayoutChangeHint hint);
void onLayoutChanged(const QList<QPersistentModelIndex>& sourceParents, QAbstractItemModel::LayoutChangeHint hint);
void onRowsMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow);
QScopedPointer<WritableProxyModelPrivate> d;
friend class WritableProxyModelPrivate;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff