QmlDesigner: Add row id to the collection table

Task-number: QDS-10621
Change-Id: Ib41f7b9a8ce8d19c24b7580887f7c44a7f87fbdc
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2023-10-06 18:50:32 +03:00
parent 8d4e103eac
commit 82be17c2c6
3 changed files with 236 additions and 167 deletions

View File

@@ -36,7 +36,9 @@ namespace QmlDesigner {
SingleCollectionModel::SingleCollectionModel(QObject *parent)
: QAbstractTableModel(parent)
{}
{
connect(this, &SingleCollectionModel::modelReset, this, &SingleCollectionModel::updateEmpty);
}
QHash<int, QByteArray> SingleCollectionModel::roleNames() const
{
@@ -117,6 +119,9 @@ QVariant SingleCollectionModel::headerData(int section,
if (orientation == Qt::Horizontal)
return m_currentCollection.headerAt(section);
if (orientation == Qt::Vertical)
return section + 1;
return {};
}
@@ -203,6 +208,15 @@ void SingleCollectionModel::loadCollection(const ModelNode &sourceNode, const QS
}
}
void SingleCollectionModel::updateEmpty()
{
bool isEmptyNow = rowCount() == 0;
if (m_isEmpty != isEmptyNow) {
m_isEmpty = isEmptyNow;
emit isEmptyChanged(m_isEmpty);
}
}
void SingleCollectionModel::switchToCollection(const CollectionReference &collection)
{
if (m_currentCollection.reference() == collection)

View File

@@ -18,6 +18,7 @@ class SingleCollectionModel : public QAbstractTableModel
Q_PROPERTY(QString collectionName MEMBER m_collectionName NOTIFY collectionNameChanged)
Q_PROPERTY(int selectedColumn READ selectedColumn WRITE selectColumn NOTIFY selectedColumnChanged)
Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged)
public:
enum DataRoles { SelectedRole = Qt::UserRole + 1 };
@@ -51,6 +52,10 @@ public:
signals:
void collectionNameChanged(const QString &collectionName);
void selectedColumnChanged(int);
void isEmptyChanged(bool);
private slots:
void updateEmpty();
private:
void switchToCollection(const CollectionReference &collection);
@@ -63,6 +68,7 @@ private:
QHash<CollectionReference, CollectionDetails> m_openedCollections;
CollectionDetails m_currentCollection;
bool m_isEmpty = true;
int m_selectedColumn = -1;
QString m_collectionName;