fix: Updates based on comments
This commit is contained in:
parent
6da897e733
commit
56f194c96c
|
@ -74,7 +74,7 @@ Item {
|
||||||
|
|
||||||
RowLayout{
|
RowLayout{
|
||||||
Button {
|
Button {
|
||||||
text: "Insert"
|
text: "Insert at"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
listModel.insert(parseInt(insertIndex.text),{
|
listModel.insert(parseInt(insertIndex.text),{
|
||||||
name: "Item " + (listModel.count + 1),
|
name: "Item " + (listModel.count + 1),
|
||||||
|
@ -84,21 +84,21 @@ Item {
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: insertIndex
|
id: insertIndex
|
||||||
text: "Insert at"
|
text: "0"
|
||||||
cursorVisible: false
|
cursorVisible: false
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RowLayout{
|
RowLayout{
|
||||||
Button {
|
Button {
|
||||||
text: "Remove"
|
text: "Remove at"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
listModel.remove(parseInt(removeIndex.text), 1)
|
listModel.remove(parseInt(removeIndex.text), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: removeIndex
|
id: removeIndex
|
||||||
text: "Remove from"
|
text: "0"
|
||||||
cursorVisible: false
|
cursorVisible: false
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
}
|
}
|
||||||
|
@ -146,34 +146,42 @@ Item {
|
||||||
|
|
||||||
RowLayout{
|
RowLayout{
|
||||||
Button {
|
Button {
|
||||||
text: "Insert"
|
text: "Insert at"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(writableProxyModel.insert(parseInt(insertWritableIndex.text)))
|
writableProxyModel.insert(parseInt(insertWritableIndex.text), {
|
||||||
{
|
name: "Item " + (writableProxyModel.rowCount() + 1),
|
||||||
let item = writableProxyModel.get(parseInt(insertWritableIndex.text))
|
key: writableProxyModel.rowCount() + 1
|
||||||
item.name = "New " + (listView.count + 1)
|
})
|
||||||
item.key = listView.count + 1
|
|
||||||
writableProxyModel.set(parseInt(insertWritableIndex.text), item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: insertWritableIndex
|
id: insertWritableIndex
|
||||||
text: "Insert at"
|
text: "0"
|
||||||
cursorVisible: false
|
cursorVisible: false
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RowLayout{
|
RowLayout{
|
||||||
Button {
|
Button {
|
||||||
text: "Remove"
|
text: "Append"
|
||||||
|
onClicked: {
|
||||||
|
writableProxyModel.append({
|
||||||
|
name: "Item " + (writableProxyModel.rowCount() + 1),
|
||||||
|
key: writableProxyModel.rowCount() + 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RowLayout{
|
||||||
|
Button {
|
||||||
|
text: "Remove from"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
writableProxyModel.remove(parseInt(removeWritableIndex.text))
|
writableProxyModel.remove(parseInt(removeWritableIndex.text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: removeWritableIndex
|
id: removeWritableIndex
|
||||||
text: "Remove from"
|
text: "0"
|
||||||
cursorVisible: false
|
cursorVisible: false
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ public:
|
||||||
~WritableProxyModel();
|
~WritableProxyModel();
|
||||||
|
|
||||||
Q_INVOKABLE QVariantMap toVariantMap() const;
|
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);
|
Q_INVOKABLE bool remove(int at);
|
||||||
//Returns a VariantMap of the data at the given index
|
//Returns a VariantMap of the data at the given index
|
||||||
//The map contains the role names as keys and the data as values
|
//The map contains the role names as keys and the data as values
|
||||||
|
@ -46,50 +47,44 @@ public:
|
||||||
//QAbstractProxyModel overrides
|
//QAbstractProxyModel overrides
|
||||||
void setSourceModel(QAbstractItemModel* sourceModel) override;
|
void setSourceModel(QAbstractItemModel* sourceModel) override;
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
int rowCount(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;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) 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 setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
|
||||||
|
|
||||||
bool removeRows(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;
|
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) 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 sibling(int row, int column, const QModelIndex& idx) const override;
|
||||||
QModelIndex parent(const QModelIndex &child) const override;
|
QModelIndex parent(const QModelIndex& child) const override;
|
||||||
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
|
QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
|
||||||
QModelIndex mapFromSource(const QModelIndex &sourceIndex) 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;
|
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:
|
signals:
|
||||||
void dirtyChanged();
|
void dirtyChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDirty(bool flag);
|
void setDirty(bool flag);
|
||||||
|
|
||||||
void handleSourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
|
void onSourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
|
||||||
void handleRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
|
void onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end);
|
||||||
void handleRowsInserted(const QModelIndex &parent, int first, int last);
|
void onRowsInserted(const QModelIndex& parent, int first, int last);
|
||||||
void handleRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
|
||||||
void handleRowsRemoved(const QModelIndex &parent, int first, int last);
|
void onRowsRemoved(const QModelIndex& parent, int first, int last);
|
||||||
void handleModelAboutToBeReset();
|
void onModelAboutToBeReset();
|
||||||
void handleModelReset();
|
void onModelReset();
|
||||||
void handleLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint);
|
void onLayoutAboutToBeChanged(const QList<QPersistentModelIndex>& sourceParents, QAbstractItemModel::LayoutChangeHint hint);
|
||||||
void handleLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint);
|
void onLayoutChanged(const QList<QPersistentModelIndex>& sourceParents, QAbstractItemModel::LayoutChangeHint hint);
|
||||||
void handleRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow);
|
void onRowsMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow);
|
||||||
|
|
||||||
bool m_dirty{false};
|
|
||||||
|
|
||||||
QScopedPointer<WritableProxyModelPrivate> d;
|
QScopedPointer<WritableProxyModelPrivate> d;
|
||||||
friend class WritableProxyModelPrivate;
|
friend class WritableProxyModelPrivate;
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue