forked from qt-creator/qt-creator
QmlDesigner: Cleanup item library
Change-Id: I863ae9a3e84ee6af7be56fa8ebf5a350f8e2db34 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -63,8 +63,7 @@ void ItemLibraryModel::setExpanded(bool expanded, const QString §ion)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemLibraryModel::ItemLibraryModel(QObject *parent)
|
ItemLibraryModel::ItemLibraryModel(QObject *parent)
|
||||||
: QAbstractListModel(parent),
|
: QAbstractListModel(parent)
|
||||||
m_nextLibId(0)
|
|
||||||
{
|
{
|
||||||
addRoleNames();
|
addRoleNames();
|
||||||
}
|
}
|
||||||
@@ -76,17 +75,17 @@ ItemLibraryModel::~ItemLibraryModel()
|
|||||||
|
|
||||||
int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
|
int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
|
||||||
{
|
{
|
||||||
return m_sectionModels.count();
|
return m_sections.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() +1 > m_sectionModels.count())
|
if (!index.isValid() || index.row() +1 > m_sections.count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
|
|
||||||
if (m_roleNames.contains(role)) {
|
if (m_roleNames.contains(role)) {
|
||||||
QVariant value = m_sectionModels.at(index.row())->property(m_roleNames.value(role));
|
QVariant value = m_sections.at(index.row())->property(m_roleNames.value(role));
|
||||||
|
|
||||||
ItemLibrarySectionModel* model = qobject_cast<ItemLibrarySectionModel *>(value.value<QObject*>());
|
ItemLibrarySectionModel* model = qobject_cast<ItemLibrarySectionModel *>(value.value<QObject*>());
|
||||||
if (model)
|
if (model)
|
||||||
@@ -140,7 +139,6 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
QMap<QString, int> sections;
|
QMap<QString, int> sections;
|
||||||
|
|
||||||
clearSections();
|
clearSections();
|
||||||
m_nextLibId = 0;
|
|
||||||
|
|
||||||
QStringList imports;
|
QStringList imports;
|
||||||
foreach (const Import &import, model->imports())
|
foreach (const Import &import, model->imports())
|
||||||
@@ -161,7 +159,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
|
|
||||||
if (sectionModel == 0) {
|
if (sectionModel == 0) {
|
||||||
sectionModel = new ItemLibrarySection(itemSectionName, this);
|
sectionModel = new ItemLibrarySection(itemSectionName, this);
|
||||||
m_sectionModels.append(sectionModel);
|
m_sections.append(sectionModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemModel = new ItemLibraryItem(sectionModel);
|
itemModel = new ItemLibraryItem(sectionModel);
|
||||||
@@ -190,14 +188,14 @@ QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntr
|
|||||||
|
|
||||||
QList<ItemLibrarySection *> ItemLibraryModel::sections() const
|
QList<ItemLibrarySection *> ItemLibraryModel::sections() const
|
||||||
{
|
{
|
||||||
return m_sectionModels;
|
return m_sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryModel::clearSections()
|
void ItemLibraryModel::clearSections()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(m_sectionModels);
|
qDeleteAll(m_sections);
|
||||||
m_sectionModels.clear();
|
m_sections.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,33 +205,9 @@ void ItemLibraryModel::registerQmlTypes()
|
|||||||
qmlRegisterType<QmlDesigner::ItemLibraryModel>();
|
qmlRegisterType<QmlDesigner::ItemLibraryModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemLibraryModel::visibleSectionCount() const
|
|
||||||
{
|
|
||||||
int visibleCount = 0;
|
|
||||||
|
|
||||||
foreach (ItemLibrarySection *section, m_sectionModels) {
|
|
||||||
if (section->isVisible())
|
|
||||||
++visibleCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return visibleCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<ItemLibrarySection *> ItemLibraryModel::visibleSections() const
|
|
||||||
{
|
|
||||||
QList<ItemLibrarySection *> visibleSectionList;
|
|
||||||
|
|
||||||
foreach (ItemLibrarySection *section, m_sectionModels) {
|
|
||||||
if (section->isVisible())
|
|
||||||
visibleSectionList.append(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
return visibleSectionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemLibrarySection *ItemLibraryModel::sectionByName(const QString §ionName)
|
ItemLibrarySection *ItemLibraryModel::sectionByName(const QString §ionName)
|
||||||
{
|
{
|
||||||
foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) {
|
foreach (ItemLibrarySection *itemLibrarySection, m_sections) {
|
||||||
if (itemLibrarySection->sectionName() == sectionName)
|
if (itemLibrarySection->sectionName() == sectionName)
|
||||||
return itemLibrarySection;
|
return itemLibrarySection;
|
||||||
}
|
}
|
||||||
@@ -245,7 +219,7 @@ void ItemLibraryModel::updateVisibility()
|
|||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) {
|
foreach (ItemLibrarySection *itemLibrarySection, m_sections) {
|
||||||
QString sectionSearchText = m_searchText;
|
QString sectionSearchText = m_searchText;
|
||||||
|
|
||||||
if (itemLibrarySection->sectionName().toLower().contains(m_searchText))
|
if (itemLibrarySection->sectionName().toLower().contains(m_searchText))
|
||||||
@@ -280,28 +254,6 @@ void ItemLibraryModel::resetModel()
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry)
|
|
||||||
{
|
|
||||||
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())
|
|
||||||
{
|
|
||||||
if (property.name() == "width")
|
|
||||||
return property.value().toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ItemLibraryModel::getHeight(const ItemLibraryEntry &itemLibraryEntry)
|
|
||||||
{
|
|
||||||
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())
|
|
||||||
{
|
|
||||||
if (property.name() == "height")
|
|
||||||
return property.value().toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerQmlTypes()
|
void registerQmlTypes()
|
||||||
{
|
{
|
||||||
registerItemLibrarySortedModel();
|
registerItemLibrarySortedModel();
|
||||||
|
@@ -87,16 +87,12 @@ private: // functions
|
|||||||
void addRoleNames();
|
void addRoleNames();
|
||||||
void resetModel();
|
void resetModel();
|
||||||
|
|
||||||
int getWidth(const ItemLibraryEntry &entry);
|
|
||||||
int getHeight(const ItemLibraryEntry &entry);
|
|
||||||
|
|
||||||
private: // variables
|
private: // variables
|
||||||
QList<ItemLibrarySection*> m_sectionModels;
|
QList<ItemLibrarySection*> m_sections;
|
||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
|
|
||||||
QString m_searchText;
|
QString m_searchText;
|
||||||
QSize m_itemIconSize;
|
|
||||||
int m_nextLibId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -40,8 +40,6 @@ ItemLibrarySection::ItemLibrarySection(const QString §ionName, QObject *pare
|
|||||||
m_sectionExpanded(true),
|
m_sectionExpanded(true),
|
||||||
m_isVisible(true)
|
m_isVisible(true)
|
||||||
{
|
{
|
||||||
// if (collapsedStateHash.contains(sectionName))
|
|
||||||
// m_sectionExpanded= collapsedStateHash.value(sectionName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -92,7 +92,6 @@ void ItemLibrarySectionModel::resetModel()
|
|||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit dataChanged(QModelIndex(), QModelIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibrarySectionModel::addRoleNames()
|
void ItemLibrarySectionModel::addRoleNames()
|
||||||
@@ -107,28 +106,4 @@ void ItemLibrarySectionModel::addRoleNames()
|
|||||||
setRoleNames(m_roleNames);
|
setRoleNames(m_roleNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemLibrarySectionModel::visibleItemCount() const
|
|
||||||
{
|
|
||||||
int visibleItemCount = 0;
|
|
||||||
|
|
||||||
foreach (ItemLibraryItem *itemLibraryItem, m_itemList) {
|
|
||||||
if (itemLibraryItem->isVisible())
|
|
||||||
visibleItemCount += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return visibleItemCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QList<ItemLibraryItem *> ItemLibrarySectionModel::visibleItems() const
|
|
||||||
{
|
|
||||||
QList<ItemLibraryItem *> visibleItemList;
|
|
||||||
|
|
||||||
foreach (ItemLibraryItem *itemLibraryItem, m_itemList) {
|
|
||||||
if (itemLibraryItem->isVisible())
|
|
||||||
visibleItemList.append(itemLibraryItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return visibleItemList;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -59,8 +59,6 @@ public:
|
|||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
void addRoleNames();
|
void addRoleNames();
|
||||||
int visibleItemCount() const;
|
|
||||||
const QList<ItemLibraryItem *> visibleItems() const;
|
|
||||||
|
|
||||||
private: // variables
|
private: // variables
|
||||||
QList<ItemLibraryItem*> m_itemList;
|
QList<ItemLibraryItem*> m_itemList;
|
||||||
|
Reference in New Issue
Block a user