forked from qt-creator/qt-creator
QmlDesigner: Change ItemLibrarySectionModel to list
Change-Id: I04932ff50e0e4f8a1eda72df35e9ba675ae2709e Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -162,24 +162,17 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
||||
&& (entry.requiredImport().isEmpty()
|
||||
|| model->hasImport(entryToImport(entry), true, true))) {
|
||||
QString itemSectionName = entry.category();
|
||||
ItemLibrarySection *sectionModel;
|
||||
ItemLibrarySection *sectionModel = sectionByName(itemSectionName);
|
||||
ItemLibraryItem *itemModel;
|
||||
int itemId = m_nextLibId++, sectionId;
|
||||
|
||||
if (sections.contains(itemSectionName)) {
|
||||
sectionId = sections.value(itemSectionName);
|
||||
sectionModel = section(sectionId);
|
||||
} else {
|
||||
sectionId = m_nextLibId++;
|
||||
sectionModel = new ItemLibrarySection(sectionId, itemSectionName, this);
|
||||
addSection(sectionModel, sectionId);
|
||||
sections.insert(itemSectionName, sectionId);
|
||||
if (sectionModel == 0) {
|
||||
sectionModel = new ItemLibrarySection(itemSectionName, this);
|
||||
m_sectionModels.append(sectionModel);
|
||||
}
|
||||
|
||||
itemModel = new ItemLibraryItem(sectionModel);
|
||||
itemModel->setItemLibraryEntry(entry);
|
||||
sectionModel->addSectionEntry(itemModel);
|
||||
m_sections.insert(itemId, sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,20 +193,9 @@ QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntr
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
ItemLibrarySection *ItemLibraryModel::section(int libraryId)
|
||||
{
|
||||
return m_sectionModels.value(libraryId);
|
||||
}
|
||||
|
||||
QList<ItemLibrarySection *> ItemLibraryModel::sections() const
|
||||
{
|
||||
return m_sectionModels.values();
|
||||
}
|
||||
|
||||
void ItemLibraryModel::addSection(ItemLibrarySection *sectionModel, int sectionId)
|
||||
{
|
||||
m_sectionModels.insert(sectionId, sectionModel);
|
||||
sectionModel->setVisible(true);
|
||||
return m_sectionModels;
|
||||
}
|
||||
|
||||
void ItemLibraryModel::clearSections()
|
||||
@@ -234,12 +216,9 @@ int ItemLibraryModel::visibleSectionCount() const
|
||||
{
|
||||
int visibleCount = 0;
|
||||
|
||||
auto sectionIterator = m_sectionModels.constBegin();
|
||||
while (sectionIterator != m_sectionModels.constEnd()) {
|
||||
ItemLibrarySection *sectionModel = sectionIterator.value();
|
||||
if (sectionModel->isVisible())
|
||||
foreach (ItemLibrarySection *section, m_sectionModels) {
|
||||
if (section->isVisible())
|
||||
++visibleCount;
|
||||
++sectionIterator;
|
||||
}
|
||||
|
||||
return visibleCount;
|
||||
@@ -249,43 +228,43 @@ QList<ItemLibrarySection *> ItemLibraryModel::visibleSections() const
|
||||
{
|
||||
QList<ItemLibrarySection *> visibleSectionList;
|
||||
|
||||
auto sectionIterator = m_sectionModels.constBegin();
|
||||
while (sectionIterator != m_sectionModels.constEnd()) {
|
||||
ItemLibrarySection *sectionModel = sectionIterator.value();
|
||||
if (sectionModel->isVisible())
|
||||
visibleSectionList.append(sectionModel);
|
||||
++sectionIterator;
|
||||
foreach (ItemLibrarySection *section, m_sectionModels) {
|
||||
if (section->isVisible())
|
||||
visibleSectionList.append(section);
|
||||
}
|
||||
|
||||
return visibleSectionList;
|
||||
}
|
||||
|
||||
ItemLibrarySection *ItemLibraryModel::sectionByName(const QString §ionName)
|
||||
{
|
||||
foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) {
|
||||
if (itemLibrarySection->sectionName() == sectionName)
|
||||
return itemLibrarySection;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ItemLibraryModel::updateVisibility()
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
bool changed = false;
|
||||
|
||||
auto sectionIterator = m_sectionModels.constBegin();
|
||||
while (sectionIterator != m_sectionModels.constEnd()) {
|
||||
ItemLibrarySection *sectionModel = sectionIterator.value();
|
||||
|
||||
foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) {
|
||||
QString sectionSearchText = m_searchText;
|
||||
|
||||
if (sectionModel->sectionName().toLower().contains(m_searchText))
|
||||
if (itemLibrarySection->sectionName().toLower().contains(m_searchText))
|
||||
sectionSearchText.clear();
|
||||
|
||||
bool sectionChanged = false,
|
||||
sectionVisibility = sectionModel->updateSectionVisibility(sectionSearchText,
|
||||
sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
|
||||
§ionChanged);
|
||||
if (sectionChanged) {
|
||||
if (sectionChanged)
|
||||
changed = true;
|
||||
if (sectionVisibility)
|
||||
emit sectionVisibilityChanged(sectionIterator.key());
|
||||
}
|
||||
|
||||
changed |= sectionModel->setVisible(sectionVisibility);
|
||||
++sectionIterator;
|
||||
changed |= itemLibrarySection->setVisible(sectionVisibility);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
|
@@ -62,9 +62,7 @@ public:
|
||||
|
||||
QMimeData *getMimeData(const ItemLibraryEntry &itemLibraryEntry);
|
||||
|
||||
ItemLibrarySection* section(int libraryId);
|
||||
QList<ItemLibrarySection*> sections() const;
|
||||
void addSection(ItemLibrarySection *sectionModel, int sectionId);
|
||||
|
||||
void clearSections();
|
||||
|
||||
@@ -73,6 +71,8 @@ public:
|
||||
int visibleSectionCount() const;
|
||||
QList<ItemLibrarySection*> visibleSections() const;
|
||||
|
||||
ItemLibrarySection *sectionByName(const QString §ionName);
|
||||
|
||||
public slots:
|
||||
void setSearchText(const QString &searchText);
|
||||
|
||||
@@ -93,7 +93,7 @@ private: // functions
|
||||
int getHeight(const ItemLibraryEntry &entry);
|
||||
|
||||
private: // variables
|
||||
QMap<int, ItemLibrarySection*> m_sectionModels;
|
||||
QList<ItemLibrarySection*> m_sectionModels;
|
||||
QMap<int, int> m_sections;
|
||||
QHash<int, QByteArray> m_roleNames;
|
||||
|
||||
|
@@ -33,13 +33,12 @@
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
ItemLibrarySection::ItemLibrarySection(int sectionLibId, const QString §ionName, QObject *parent)
|
||||
ItemLibrarySection::ItemLibrarySection(const QString §ionName, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_sectionEntries(parent),
|
||||
m_name(sectionName),
|
||||
m_sectionLibraryId(sectionLibId),
|
||||
m_sectionExpanded(true),
|
||||
m_isVisible(false)
|
||||
m_isVisible(true)
|
||||
{
|
||||
// if (collapsedStateHash.contains(sectionName))
|
||||
// m_sectionExpanded= collapsedStateHash.value(sectionName);
|
||||
@@ -51,11 +50,6 @@ QString ItemLibrarySection::sectionName() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
int ItemLibrarySection::sectionLibraryId() const
|
||||
{
|
||||
return m_sectionLibraryId;
|
||||
}
|
||||
|
||||
bool ItemLibrarySection::sectionExpanded() const
|
||||
{
|
||||
return m_sectionExpanded;
|
||||
|
@@ -44,10 +44,9 @@ class ItemLibrarySection: public QObject {
|
||||
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
|
||||
|
||||
public:
|
||||
ItemLibrarySection(int sectionLibraryId, const QString §ionName, QObject *parent = 0);
|
||||
ItemLibrarySection(const QString §ionName, QObject *parent = 0);
|
||||
|
||||
QString sectionName() const;
|
||||
int sectionLibraryId() const;
|
||||
bool sectionExpanded() const;
|
||||
QVariant sortingRole() const;
|
||||
|
||||
@@ -65,7 +64,6 @@ signals:
|
||||
private:
|
||||
ItemLibrarySectionModel m_sectionEntries;
|
||||
QString m_name;
|
||||
int m_sectionLibraryId;
|
||||
bool m_sectionExpanded;
|
||||
bool m_isVisible;
|
||||
};
|
||||
|
Reference in New Issue
Block a user