forked from qt-creator/qt-creator
QmlDesigner: fix a rarely happen crash
It was difficult to reproduce, but happen regular while importing something from design tools. Task-number: QTCREATORBUG-23707 Change-Id: I93e8c8cf9d44ecf20f5754ae48a0599f056a8610 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QMetaProperty>
|
#include <QMetaProperty>
|
||||||
@@ -290,13 +291,15 @@ void ItemLibraryModel::addRoleNames()
|
|||||||
|
|
||||||
void ItemLibraryModel::sortSections()
|
void ItemLibraryModel::sortSections()
|
||||||
{
|
{
|
||||||
|
int nullPointerSectionCount = m_sections.removeAll(QPointer<ItemLibrarySection>());
|
||||||
|
QTC_ASSERT(nullPointerSectionCount == 0,;);
|
||||||
auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) {
|
auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) {
|
||||||
return QString::localeAwareCompare(first->sortingName(), second->sortingName()) < 1;
|
return QString::localeAwareCompare(first->sortingName(), second->sortingName()) < 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::sort(m_sections.begin(), m_sections.end(), sectionSort);
|
std::sort(m_sections.begin(), m_sections.end(), sectionSort);
|
||||||
|
|
||||||
foreach (ItemLibrarySection *itemLibrarySection, m_sections)
|
for (auto itemLibrarySection : m_sections)
|
||||||
itemLibrarySection->sortItems();
|
itemLibrarySection->sortItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ bool ItemLibrarySection::updateSectionVisibility(const QString &searchText, bool
|
|||||||
|
|
||||||
*changed = false;
|
*changed = false;
|
||||||
|
|
||||||
foreach(ItemLibraryItem *itemLibraryItem, m_sectionEntries.items()) {
|
for (auto itemLibraryItem : m_sectionEntries.items()) {
|
||||||
bool itemVisible = itemLibraryItem->itemName().toLower().contains(searchText)
|
bool itemVisible = itemLibraryItem->itemName().toLower().contains(searchText)
|
||||||
|| itemLibraryItem->typeName().toLower().contains(searchText);
|
|| itemLibraryItem->typeName().toLower().contains(searchText);
|
||||||
|
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "itemlibraryitem.h"
|
#include "itemlibraryitem.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -79,13 +81,15 @@ void ItemLibrarySectionModel::addItem(ItemLibraryItem *element)
|
|||||||
element->setVisible(true);
|
element->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<ItemLibraryItem *> &ItemLibrarySectionModel::items() const
|
const QList<QPointer<ItemLibraryItem>> &ItemLibrarySectionModel::items() const
|
||||||
{
|
{
|
||||||
return m_itemList;
|
return m_itemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibrarySectionModel::sortItems()
|
void ItemLibrarySectionModel::sortItems()
|
||||||
{
|
{
|
||||||
|
int nullPointerSectionCount = m_itemList.removeAll(QPointer<ItemLibraryItem>());
|
||||||
|
QTC_ASSERT(nullPointerSectionCount == 0,;);
|
||||||
auto itemSort = [](ItemLibraryItem *first, ItemLibraryItem *second) {
|
auto itemSort = [](ItemLibraryItem *first, ItemLibraryItem *second) {
|
||||||
return QString::localeAwareCompare(first->itemName(), second->itemName()) < 1;
|
return QString::localeAwareCompare(first->itemName(), second->itemName()) < 1;
|
||||||
};
|
};
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "itemlibrarymodel.h"
|
#include "itemlibrarymodel.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ public:
|
|||||||
|
|
||||||
void addItem(ItemLibraryItem *item);
|
void addItem(ItemLibraryItem *item);
|
||||||
|
|
||||||
const QList<ItemLibraryItem *> &items() const;
|
const QList<QPointer<ItemLibraryItem> > &items() const;
|
||||||
|
|
||||||
void sortItems();
|
void sortItems();
|
||||||
void resetModel();
|
void resetModel();
|
||||||
@@ -56,7 +57,7 @@ private: // functions
|
|||||||
void addRoleNames();
|
void addRoleNames();
|
||||||
|
|
||||||
private: // variables
|
private: // variables
|
||||||
QList<ItemLibraryItem*> m_itemList;
|
QList<QPointer<ItemLibraryItem>> m_itemList;
|
||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user