forked from quickshell/quickshell
core/objectmodel: add signals for changes to the list
This commit is contained in:
parent
06240ccf80
commit
5a84e73442
|
@ -39,21 +39,28 @@ QObject* UntypedObjectModel::valueAt(QQmlListProperty<QObject>* property, qsizet
|
||||||
|
|
||||||
void UntypedObjectModel::insertObject(QObject* object, qsizetype index) {
|
void UntypedObjectModel::insertObject(QObject* object, qsizetype index) {
|
||||||
auto iindex = index == -1 ? this->valuesList.length() : index;
|
auto iindex = index == -1 ? this->valuesList.length() : index;
|
||||||
auto intIndex = static_cast<qint32>(iindex);
|
emit this->objectInsertedPre(object, index);
|
||||||
|
|
||||||
|
auto intIndex = static_cast<qint32>(iindex);
|
||||||
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
|
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
|
||||||
this->valuesList.insert(iindex, object);
|
this->valuesList.insert(iindex, object);
|
||||||
this->endInsertRows();
|
this->endInsertRows();
|
||||||
|
|
||||||
emit this->valuesChanged();
|
emit this->valuesChanged();
|
||||||
|
emit this->objectInsertedPost(object, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UntypedObjectModel::removeAt(qsizetype index) {
|
void UntypedObjectModel::removeAt(qsizetype index) {
|
||||||
auto intIndex = static_cast<qint32>(index);
|
auto* object = this->valuesList.at(index);
|
||||||
|
emit this->objectRemovedPre(object, index);
|
||||||
|
|
||||||
|
auto intIndex = static_cast<qint32>(index);
|
||||||
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
|
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
|
||||||
this->valuesList.removeAt(index);
|
this->valuesList.removeAt(index);
|
||||||
this->endRemoveRows();
|
this->endRemoveRows();
|
||||||
|
|
||||||
emit this->valuesChanged();
|
emit this->valuesChanged();
|
||||||
|
emit this->objectRemovedPost(object, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UntypedObjectModel::removeObject(const QObject* object) {
|
bool UntypedObjectModel::removeObject(const QObject* object) {
|
||||||
|
|
|
@ -57,6 +57,14 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void valuesChanged();
|
void valuesChanged();
|
||||||
|
/// Sent immediately before an object is inserted into the list.
|
||||||
|
void objectInsertedPre(QObject* object, qsizetype index);
|
||||||
|
/// Sent immediately after an object is inserted into the list.
|
||||||
|
void objectInsertedPost(QObject* object, qsizetype index);
|
||||||
|
/// Sent immediately before an object is removed from the list.
|
||||||
|
void objectRemovedPre(QObject* object, qsizetype index);
|
||||||
|
/// Sent immediately after an object is removed from the list.
|
||||||
|
void objectRemovedPost(QObject* object, qsizetype index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void insertObject(QObject* object, qsizetype index = -1);
|
void insertObject(QObject* object, qsizetype index = -1);
|
||||||
|
|
Loading…
Reference in a new issue