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
0d163379
Commit
0d163379
authored
Jul 15, 2010
by
Lasse Holmstedt
Browse files
Changed handling of selected items to use weak pointers
graphics items could be destroyed after selecting something.
parent
28867b78
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/tools/qml/qmlobserver/editor/abstractformeditortool.cpp
View file @
0d163379
...
...
@@ -60,15 +60,14 @@ QGraphicsScene* AbstractFormEditorTool::scene() const
return
view
()
->
scene
();
}
void
AbstractFormEditorTool
::
setItems
(
const
QList
<
QGraphicsItem
*>
&
itemList
)
void
AbstractFormEditorTool
::
updateSelectedItems
(
)
{
m_itemList
=
itemList
;
selectedItemsChanged
(
m_itemList
);
selectedItemsChanged
(
items
());
}
QList
<
QGraphicsItem
*>
AbstractFormEditorTool
::
items
()
const
{
return
m_itemList
;
return
view
()
->
selectedItems
()
;
}
bool
AbstractFormEditorTool
::
topItemIsMovable
(
const
QList
<
QGraphicsItem
*>
&
itemList
)
...
...
src/tools/qml/qmlobserver/editor/abstractformeditortool.h
View file @
0d163379
...
...
@@ -74,7 +74,7 @@ public:
virtual
void
clear
()
=
0
;
virtual
void
graphicsObjectsChanged
(
const
QList
<
QGraphicsObject
*>
&
itemList
)
=
0
;
void
setItems
(
const
QList
<
QGraphicsItem
*>
&
itemList
);
void
updateSelectedItems
(
);
QList
<
QGraphicsItem
*>
items
()
const
;
bool
topItemIsMovable
(
const
QList
<
QGraphicsItem
*>
&
itemList
);
...
...
@@ -89,7 +89,7 @@ public:
static
QDeclarativeItem
*
toQDeclarativeItem
(
QGraphicsItem
*
item
);
protected:
virtual
void
selectedItemsChanged
(
const
QList
<
QGraphicsItem
*>
&
item
List
)
=
0
;
virtual
void
selectedItemsChanged
(
const
QList
<
QGraphicsItem
*>
&
object
List
)
=
0
;
QDeclarativeDesignView
*
view
()
const
;
QGraphicsScene
*
scene
()
const
;
...
...
src/tools/qml/qmlobserver/qdeclarativedesignview.cpp
View file @
0d163379
...
...
@@ -262,13 +262,29 @@ void QDeclarativeDesignView::changeTool(Constants::DesignTool tool, Constants::T
void
QDeclarativeDesignView
::
setSelectedItems
(
QList
<
QGraphicsItem
*>
items
)
{
m_currentSelection
=
items
;
m_currentTool
->
setItems
(
items
);
m_currentSelection
.
clear
();
foreach
(
QGraphicsItem
*
item
,
items
)
{
if
(
item
)
{
QGraphicsObject
*
obj
=
item
->
toGraphicsObject
();
if
(
obj
)
m_currentSelection
<<
obj
;
}
}
m_currentTool
->
updateSelectedItems
();
}
QList
<
QGraphicsItem
*>
QDeclarativeDesignView
::
selectedItems
()
const
QList
<
QGraphicsItem
*>
QDeclarativeDesignView
::
selectedItems
()
{
return
m_currentSelection
;
QList
<
QGraphicsItem
*>
selection
;
foreach
(
const
QWeakPointer
<
QGraphicsObject
>
&
selectedObject
,
m_currentSelection
)
{
if
(
selectedObject
.
isNull
())
{
m_currentSelection
.
removeOne
(
selectedObject
);
}
else
{
selection
<<
selectedObject
.
data
();
}
}
return
selection
;
}
AbstractFormEditorTool
*
QDeclarativeDesignView
::
currentTool
()
const
...
...
@@ -333,8 +349,6 @@ QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QRectF &scen
void
QDeclarativeDesignView
::
changeToSingleSelectTool
()
{
//qDebug() << "changing to selection tool";
m_currentToolMode
=
Constants
::
SelectionToolMode
;
m_selectionTool
->
setRubberbandSelectionMode
(
false
);
...
...
@@ -352,7 +366,7 @@ void QDeclarativeDesignView::changeToSelectTool()
m_currentTool
->
clear
();
m_currentTool
=
m_selectionTool
;
m_currentTool
->
clear
();
m_currentTool
->
setItems
(
m_currentSelection
);
m_currentTool
->
updateSelectedItems
(
);
}
void
QDeclarativeDesignView
::
changeToMarqueeSelectTool
()
...
...
src/tools/qml/qmlobserver/qdeclarativedesignview.h
View file @
0d163379
...
...
@@ -3,6 +3,7 @@
#include "qmlviewerconstants.h"
#include <qdeclarativeview.h>
#include <QWeakPointer>
QT_FORWARD_DECLARE_CLASS
(
QDeclarativeItem
);
QT_FORWARD_DECLARE_CLASS
(
QMouseEvent
);
...
...
@@ -32,7 +33,7 @@ public:
~
QDeclarativeDesignView
();
void
setSelectedItems
(
QList
<
QGraphicsItem
*>
items
);
QList
<
QGraphicsItem
*>
selectedItems
()
const
;
QList
<
QGraphicsItem
*>
selectedItems
();
AbstractFormEditorTool
*
currentTool
()
const
;
LayerItem
*
manipulatorLayer
()
const
;
...
...
@@ -102,7 +103,7 @@ private:
private:
QPointF
m_cursorPos
;
QList
<
Q
GraphicsItem
*
>
m_currentSelection
;
QList
<
Q
WeakPointer
<
QGraphicsObject
>
>
m_currentSelection
;
Constants
::
DesignTool
m_currentToolMode
;
AbstractFormEditorTool
*
m_currentTool
;
...
...
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