Commit d38eabac authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen
Browse files

QmlDesigner: Add sorting to item library



Task-number: QTCREATORBUG-12603
Change-Id: I883a343d2d7c6cd563d383f7833881db563a0e4a
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 1b312869
......@@ -52,11 +52,6 @@ QString ItemLibraryItem::itemLibraryIconPath() const
return QStringLiteral("image://qmldesigner_itemlibrary/") + m_itemLibraryEntry.libraryEntryIconPath();
}
QVariant ItemLibraryItem::sortingRole() const
{
return itemName();
}
bool ItemLibraryItem::setVisible(bool isVisible)
{
if (isVisible != m_isVisible) {
......
......@@ -46,7 +46,6 @@ class ItemLibraryItem: public QObject {
Q_PROPERTY(QVariant itemLibraryEntry READ itemLibraryEntry FINAL)
Q_PROPERTY(QString itemName READ itemName FINAL)
Q_PROPERTY(QString itemLibraryIconPath READ itemLibraryIconPath FINAL)
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
Q_PROPERTY(bool itemVisible READ isVisible NOTIFY visibilityChanged FINAL)
public:
......@@ -55,7 +54,6 @@ public:
QString itemName() const;
QString itemLibraryIconPath() const;
QVariant sortingRole() const;
bool setVisible(bool isVisible);
bool isVisible() const;
......
......@@ -155,19 +155,20 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|| model->hasImport(entryToImport(entry), true, true))) {
QString itemSectionName = entry.category();
ItemLibrarySection *sectionModel = sectionByName(itemSectionName);
ItemLibraryItem *itemModel;
ItemLibraryItem *item;
if (sectionModel == 0) {
sectionModel = new ItemLibrarySection(itemSectionName, this);
m_sections.append(sectionModel);
}
itemModel = new ItemLibraryItem(sectionModel);
itemModel->setItemLibraryEntry(entry);
sectionModel->addSectionEntry(itemModel);
item = new ItemLibraryItem(sectionModel);
item->setItemLibraryEntry(entry);
sectionModel->addSectionEntry(item);
}
}
sortSections();
resetModel();
updateVisibility();
}
......@@ -254,6 +255,18 @@ void ItemLibraryModel::resetModel()
endResetModel();
}
void ItemLibraryModel::sortSections()
{
auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) {
return QString::localeAwareCompare(first->sortingName(), second->sortingName()) < 1;
};
std::sort(m_sections.begin(), m_sections.end(), sectionSort);
foreach (ItemLibrarySection *itemLibrarySection, m_sections)
itemLibrarySection->sortItems();
}
void registerQmlTypes()
{
registerItemLibrarySortedModel();
......
......@@ -86,6 +86,7 @@ private: // functions
void updateVisibility();
void addRoleNames();
void resetModel();
void sortSections();
private: // variables
......
......@@ -53,11 +53,11 @@ bool ItemLibrarySection::sectionExpanded() const
return m_sectionExpanded;
}
QVariant ItemLibrarySection::sortingRole() const
QString ItemLibrarySection::sortingName() const
{
if (sectionName() == QStringLiteral("QML Components")) //Qml Components always come first
return QVariant(QStringLiteral("AA.this_comes_first"));
return QStringLiteral("aaaa");
return sectionName();
}
......@@ -111,4 +111,9 @@ bool ItemLibrarySection::isVisible() const
return m_isVisible;
}
void ItemLibrarySection::sortItems()
{
m_sectionEntries.sortItems();
}
} // namespace QmlDesigner
......@@ -42,14 +42,13 @@ class ItemLibrarySection: public QObject {
Q_PROPERTY(QString sectionName READ sectionName FINAL)
Q_PROPERTY(bool sectionVisible READ isVisible NOTIFY visibilityChanged FINAL)
Q_PROPERTY(bool sectionExpanded READ sectionExpanded FINAL)
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
public:
ItemLibrarySection(const QString &sectionName, QObject *parent = 0);
QString sectionName() const;
bool sectionExpanded() const;
QVariant sortingRole() const;
QString sortingName() const;
void addSectionEntry(ItemLibraryItem *sectionEntry);
QObject *sectionEntries();
......@@ -59,6 +58,8 @@ public:
bool setVisible(bool isVisible);
bool isVisible() const;
void sortItems();
signals:
void sectionEntriesChanged();
void visibilityChanged();
......
......@@ -88,6 +88,15 @@ const QList<ItemLibraryItem *> &ItemLibrarySectionModel::items() const
return m_itemList;
}
void ItemLibrarySectionModel::sortItems()
{
auto itemSort = [](ItemLibraryItem *first, ItemLibraryItem *second) {
return QString::localeAwareCompare(first->itemName(), second->itemName()) < 1;
};
std::sort(m_itemList.begin(), m_itemList.end(), itemSort);
}
void ItemLibrarySectionModel::resetModel()
{
beginResetModel();
......
......@@ -55,6 +55,7 @@ public:
const QList<ItemLibraryItem *> &items() const;
void sortItems();
void resetModel();
private: // functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment