Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
e4d2d8a2
Commit
e4d2d8a2
authored
Dec 10, 2010
by
Thomas Hartmann
Browse files
QmlDesigner.itemlibrary: filter item library by imports
Only show items that are available and use requiredImport for filtering
parent
8cdb63ea
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
View file @
e4d2d8a2
...
...
@@ -355,7 +355,6 @@ void DesignDocumentController::loadCurrentModel()
m_d
->
model
->
attachView
(
m_d
->
nodeInstanceView
.
data
());
m_d
->
model
->
attachView
(
m_d
->
navigator
.
data
());
m_d
->
itemLibraryView
->
widget
()
->
setItemLibraryInfo
(
m_d
->
model
->
metaInfo
().
itemLibraryInfo
());
m_d
->
itemLibraryView
->
widget
()
->
setResourcePath
(
QFileInfo
(
m_d
->
fileName
).
absolutePath
());
if
(
!
m_d
->
componentAction
)
{
...
...
src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp
View file @
e4d2d8a2
...
...
@@ -29,6 +29,8 @@
#include "itemlibrarymodel.h"
#include "itemlibraryinfo.h"
#include <model.h>
#include <nodemetainfo.h>
#include <QVariant>
#include <QMimeData>
...
...
@@ -378,7 +380,12 @@ bool ItemLibraryModel::isItemVisible(int itemLibId)
return
elementModel
(
sectionLibId
)
->
isItemVisible
(
itemLibId
);
}
void
ItemLibraryModel
::
update
(
ItemLibraryInfo
*
itemLibraryInfo
)
QString
entryToImport
(
const
ItemLibraryEntry
&
entry
)
{
return
entry
.
requiredImport
()
+
" "
+
QString
::
number
(
entry
.
majorVersion
())
+
"."
+
QString
::
number
(
entry
.
minorVersion
());
}
void
ItemLibraryModel
::
update
(
ItemLibraryInfo
*
itemLibraryInfo
,
Model
*
model
)
{
QMap
<
QString
,
int
>
sections
;
...
...
@@ -387,36 +394,46 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
m_sections
.
clear
();
m_nextLibId
=
0
;
foreach
(
ItemLibraryEntry
entry
,
itemLibraryInfo
->
entries
())
{
QString
itemSectionName
=
entry
.
category
();
ItemLibrarySectionModel
*
sectionModel
;
ItemLibraryItemModel
*
itemModel
;
int
itemId
=
m_nextLibId
++
,
sectionId
;
if
(
sections
.
contains
(
itemSectionName
))
{
sectionId
=
sections
.
value
(
itemSectionName
);
sectionModel
=
elementModel
(
sectionId
);
}
else
{
sectionId
=
m_nextLibId
++
;
sectionModel
=
new
ItemLibrarySectionModel
(
m_scriptEngine
.
data
(),
sectionId
,
itemSectionName
,
this
);
addElement
(
sectionModel
,
sectionId
);
sections
.
insert
(
itemSectionName
,
sectionId
);
}
QStringList
imports
;
foreach
(
const
Import
&
import
,
model
->
imports
())
if
(
import
.
isLibraryImport
())
imports
<<
import
.
url
()
+
" "
+
import
.
version
();
m_itemInfos
.
insert
(
itemId
,
entry
);
itemModel
=
new
ItemLibraryItemModel
(
m_scriptEngine
.
data
(),
itemId
,
entry
.
name
());
// delayed creation of (default) icons
if
(
entry
.
iconPath
().
isEmpty
())
entry
.
setIconPath
(
QLatin1String
(
":/ItemLibrary/images/item-default-icon.png"
));
if
(
entry
.
dragIcon
().
isNull
())
entry
.
setDragIcon
(
createDragPixmap
(
getWidth
(
entry
),
getHeight
(
entry
)));
foreach
(
ItemLibraryEntry
entry
,
itemLibraryInfo
->
entries
())
{
itemModel
->
setItemIconPath
(
entry
.
iconPath
());
itemModel
->
setItemIconSize
(
m_itemIconSize
);
sectionModel
->
addSectionEntry
(
itemModel
);
m_sections
.
insert
(
itemId
,
sectionId
);
bool
valid
=
model
->
metaInfo
(
entry
.
typeName
(),
entry
.
majorVersion
(),
entry
.
minorVersion
()).
isValid
();
if
(
valid
&&
entry
.
requiredImport
().
isEmpty
()
||
imports
.
contains
(
entryToImport
(
entry
)))
{
QString
itemSectionName
=
entry
.
category
();
ItemLibrarySectionModel
*
sectionModel
;
ItemLibraryItemModel
*
itemModel
;
int
itemId
=
m_nextLibId
++
,
sectionId
;
if
(
sections
.
contains
(
itemSectionName
))
{
sectionId
=
sections
.
value
(
itemSectionName
);
sectionModel
=
elementModel
(
sectionId
);
}
else
{
sectionId
=
m_nextLibId
++
;
sectionModel
=
new
ItemLibrarySectionModel
(
m_scriptEngine
.
data
(),
sectionId
,
itemSectionName
,
this
);
addElement
(
sectionModel
,
sectionId
);
sections
.
insert
(
itemSectionName
,
sectionId
);
}
m_itemInfos
.
insert
(
itemId
,
entry
);
itemModel
=
new
ItemLibraryItemModel
(
m_scriptEngine
.
data
(),
itemId
,
entry
.
name
());
// delayed creation of (default) icons
if
(
entry
.
iconPath
().
isEmpty
())
entry
.
setIconPath
(
QLatin1String
(
":/ItemLibrary/images/item-default-icon.png"
));
if
(
entry
.
dragIcon
().
isNull
())
entry
.
setDragIcon
(
createDragPixmap
(
getWidth
(
entry
),
getHeight
(
entry
)));
itemModel
->
setItemIconPath
(
entry
.
iconPath
());
itemModel
->
setItemIconSize
(
m_itemIconSize
);
sectionModel
->
addSectionEntry
(
itemModel
);
m_sections
.
insert
(
itemId
,
sectionId
);
}
}
updateVisibility
();
...
...
src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h
View file @
e4d2d8a2
...
...
@@ -42,6 +42,7 @@ namespace QmlDesigner {
class
ItemLibraryInfo
;
class
ItemLibraryEntry
;
class
Model
;
namespace
Internal
{
...
...
@@ -131,7 +132,7 @@ public:
QString
searchText
()
const
;
void
update
(
ItemLibraryInfo
*
itemLibraryInfo
);
void
update
(
ItemLibraryInfo
*
itemLibraryInfo
,
Model
*
model
);
QString
getTypeName
(
int
libId
);
QMimeData
*
getMimeData
(
int
libId
);
...
...
src/plugins/qmldesigner/components/itemlibrary/itemlibraryview.cpp
View file @
e4d2d8a2
#include "itemlibraryview.h"
#include "itemlibrarywidget.h"
#include <import.h>
namespace
QmlDesigner
{
...
...
@@ -21,19 +22,24 @@ ItemLibraryWidget *ItemLibraryView::widget()
void
ItemLibraryView
::
modelAttached
(
Model
*
model
)
{
AbstractView
::
modelAttached
(
model
);
m_widget
->
setModel
(
model
);
updateImports
();
}
void
ItemLibraryView
::
modelAboutToBeDetached
(
Model
*
model
)
{
AbstractView
::
modelAboutToBeDetached
(
model
);
m_widget
->
setModel
(
0
);
}
void
ItemLibraryView
::
importAdded
(
const
Import
&
import
)
void
ItemLibraryView
::
importAdded
(
const
Import
&
)
{
updateImports
();
}
void
ItemLibraryView
::
importRemoved
(
const
Import
&
import
)
void
ItemLibraryView
::
importRemoved
(
const
Import
&
)
{
updateImports
();
}
void
ItemLibraryView
::
nodeCreated
(
const
ModelNode
&
)
...
...
@@ -122,4 +128,9 @@ void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &)
}
void
ItemLibraryView
::
updateImports
()
{
m_widget
->
updateModel
();
}
}
//QmlDesigner
src/plugins/qmldesigner/components/itemlibrary/itemlibraryview.h
View file @
e4d2d8a2
...
...
@@ -79,6 +79,9 @@ public:
void
instancePropertyChange
(
const
QList
<
QPair
<
ModelNode
,
QString
>
>
&
propertyList
);
void
instancesCompleted
(
const
QVector
<
ModelNode
>
&
completedNodeList
);
protected:
void
updateImports
();
private:
QWeakPointer
<
ItemLibraryWidget
>
m_widget
;
};
...
...
src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp
View file @
e4d2d8a2
...
...
@@ -34,6 +34,8 @@
#include "itemlibrarymodel.h"
#include "itemlibraryimageprovider.h"
#include "customdraganddrop.h"
#include <model.h>
#include <metainfo.h>
#include <QFileInfo>
#include <QFileIconProvider>
...
...
@@ -107,6 +109,7 @@ public:
QSize
m_itemIconSize
,
m_resIconSize
;
MyFileIconProvider
m_iconProvider
;
Model
*
model
;
};
ItemLibraryWidgetPrivate
::
ItemLibraryWidgetPrivate
(
QObject
*
object
)
:
...
...
@@ -279,9 +282,16 @@ void ItemLibraryWidget::setSearchFilter(const QString &searchFilter)
}
}
void
ItemLibraryWidget
::
setModel
(
Model
*
model
)
{
m_d
->
model
=
model
;
setItemLibraryInfo
(
model
->
metaInfo
().
itemLibraryInfo
());
updateModel
();
}
void
ItemLibraryWidget
::
updateModel
()
{
m_d
->
m_itemLibraryModel
->
update
(
m_d
->
m_itemLibraryInfo
.
data
());
m_d
->
m_itemLibraryModel
->
update
(
m_d
->
m_itemLibraryInfo
.
data
()
,
m_d
->
model
);
updateSearch
();
}
...
...
src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h
View file @
e4d2d8a2
...
...
@@ -38,6 +38,7 @@ namespace QmlDesigner {
class
ItemLibraryWidgetPrivate
;
class
MetaInfo
;
class
ItemLibraryEntry
;
class
Model
;
class
ItemLibraryWidget
:
public
QFrame
{
...
...
@@ -60,6 +61,8 @@ public Q_SLOTS:
void
startDragAndDrop
(
int
itemLibId
);
void
showItemInfo
(
int
itemLibId
);
void
setModel
(
Model
*
model
);
protected:
void
wheelEvent
(
QWheelEvent
*
event
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment