Commit 3c1d6e79 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.ItemLibrary: the state of sections should be persistent

Once a section is collapsed it should stay collapsed until
it is expanded again.
Before this patch changing the document or going to text mode
did reset the state.

Change-Id: I5d3b4164cbef75276a2e0e92fb4bfa77292f73db
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 9db57f3f
......@@ -43,6 +43,8 @@ namespace QmlDesigner {
namespace Internal {
static QHash<QString, bool> collapsedStateHash;
template <class T>
ItemLibrarySortedModel<T>::ItemLibrarySortedModel(QObject *parent) :
......@@ -238,6 +240,12 @@ ItemLibrarySectionModel::ItemLibrarySectionModel(QScriptEngine *scriptEngine, in
QScriptValue::setProperty(QLatin1String("sectionName"), sectionName);
QScriptValue::setProperty(QLatin1String("sectionEntries"),
scriptEngine->newVariant(QVariant::fromValue(static_cast<QDeclarativeListModel *>(&m_sectionEntries))));
if (collapsedStateHash.contains(sectionName)) {
QScriptValue::setProperty(QLatin1String("sectionExpanded"), collapsedStateHash.value(sectionName));
} else {
QScriptValue::setProperty(QLatin1String("sectionExpanded"), true);
}
}
......@@ -310,6 +318,15 @@ bool ItemLibrarySectionModel::operator<(const ItemLibrarySectionModel &other) co
return sectionName() < other.sectionName();
}
void ItemLibraryModel::setExpanded(bool expanded, const QString &section)
{
if (collapsedStateHash.contains(section))
collapsedStateHash.remove(section);
if (!expanded) //default is true
collapsedStateHash.insert(section, expanded);
}
ItemLibraryModel::ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent)
: ItemLibrarySortedModel<ItemLibrarySectionModel>(parent),
m_scriptEngine(scriptEngine),
......
......@@ -144,6 +144,7 @@ public slots:
int getItemSectionIndex(int itemLibId);
int getSectionLibId(int itemLibId);
bool isItemVisible(int itemLibId);
void setExpanded(bool, const QString &section);
signals:
void qmlModelChanged();
......
......@@ -65,7 +65,6 @@ Rectangle {
}
function resetView() {
expandAllEntries()
scrollbar.reset()
}
......
......@@ -48,6 +48,14 @@ Column {
gridFrame.state = ""
}
Component.onCompleted: {
if (mouseArea.expandedFlag) {
gridFrame.state = ""
} else {
gridFrame.state = "shrunk"
}
}
signal itemSelected(int itemLibId)
signal itemDragged(int itemLibId)
......@@ -139,6 +147,9 @@ Column {
font.bold: true
}
MouseArea {
id: mouseArea
property bool expandedFlag: sectionExpanded
anchors.fill: parent
onClicked: gridFrame.toggleExpanded()
}
......@@ -151,6 +162,8 @@ Column {
function toggleExpanded() {
state = ((state == "")? "shrunk":"")
itemLibraryModel.setExpanded(state === "", text.text);
}
clip: true
......
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