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
SDK
Umbrello
Commits
5dc8ee09
Commit
5dc8ee09
authored
Dec 18, 2013
by
Ralf Habacker
Browse files
Use context menu event handler for list view context menu.
parent
fb221752
Changes
2
Hide whitespace changes
Inline
Side-by-side
umbrello/umllistview.cpp
View file @
5dc8ee09
...
...
@@ -87,7 +87,6 @@ UMLListView::UMLListView(QWidget *parent)
:
QTreeWidget
(
parent
),
m_rv
(
0
),
m_datatypeFolder
(
0
),
m_menu
(
0
),
m_doc
(
UMLApp
::
app
()
->
document
()),
m_bStartedCut
(
false
),
m_bStartedCopy
(
false
),
...
...
@@ -215,30 +214,6 @@ bool UMLListView::event(QEvent *e)
return
QTreeWidget
::
event
(
e
);
}
/**
* Event filter.
*/
bool
UMLListView
::
eventFilter
(
QObject
*
o
,
QEvent
*
e
)
{
if
(
e
->
type
()
!=
QEvent
::
MouseButtonPress
||
qstrcmp
(
"QHeader"
,
metaObject
()
->
className
())
!=
0
)
return
QTreeWidget
::
eventFilter
(
o
,
e
);
QMouseEvent
*
me
=
static_cast
<
QMouseEvent
*>
(
e
);
if
(
me
->
button
()
==
Qt
::
RightButton
)
{
if
(
m_menu
)
{
m_menu
->
hide
();
disconnect
(
m_menu
,
SIGNAL
(
triggered
(
QAction
*
)),
this
,
SLOT
(
popupMenuSel
(
QAction
*
)));
delete
m_menu
;
m_menu
=
0
;
}
UMLListViewItem
*
currItem
=
static_cast
<
UMLListViewItem
*>
(
currentItem
());
m_menu
=
new
ListPopupMenu
(
this
,
UMLListViewItem
::
lvt_Model
,
currItem
->
umlObject
());
m_menu
->
popup
(
me
->
globalPos
());
connect
(
m_menu
,
SIGNAL
(
triggered
(
QAction
*
)),
this
,
SLOT
(
popupMenuSel
(
QAction
*
)));
return
true
;
}
return
QTreeWidget
::
eventFilter
(
o
,
e
);
}
/**
* Handler for mouse press events.
* @param me the mouse event
...
...
@@ -279,19 +254,6 @@ void UMLListView::mousePressEvent(QMouseEvent *me)
m_dragStartPosition
=
me
->
pos
();
}
if
(
button
==
Qt
::
RightButton
)
{
if
(
m_menu
!=
0
)
{
m_menu
->
hide
();
disconnect
(
m_menu
,
SIGNAL
(
triggered
(
QAction
*
)),
this
,
SLOT
(
popupMenuSel
(
QAction
*
)));
delete
m_menu
;
m_menu
=
0
;
}
const
UMLListViewItem
::
ListViewType
type
=
item
->
type
();
m_menu
=
new
ListPopupMenu
(
this
,
type
,
item
->
umlObject
());
m_menu
->
popup
(
me
->
globalPos
());
connect
(
m_menu
,
SIGNAL
(
triggered
(
QAction
*
)),
this
,
SLOT
(
popupMenuSel
(
QAction
*
)));
}
//end if right button
QTreeWidget
::
mousePressEvent
(
me
);
}
...
...
@@ -392,7 +354,7 @@ void UMLListView::keyPressEvent(QKeyEvent *ke)
* Called when a right mouse button menu has an item selected.
* @param action the selected action
*/
void
UMLListView
::
popup
MenuSel
(
QAction
*
action
)
void
UMLListView
::
slot
MenuSel
ection
(
QAction
*
action
)
{
UMLListViewItem
*
currItem
=
static_cast
<
UMLListViewItem
*>
(
currentItem
());
if
(
!
currItem
)
{
...
...
@@ -401,7 +363,7 @@ void UMLListView::popupMenuSel(QAction* action)
}
UMLListViewItem
::
ListViewType
lvt
=
currItem
->
type
();
UMLObject
::
ObjectType
umlType
=
UMLObject
::
ot_UMLObject
;
ListPopupMenu
::
MenuType
menuType
=
m_menu
->
getMenuType
(
action
);
ListPopupMenu
::
MenuType
menuType
=
ListPopupMenu
::
typeFromAction
(
action
);
QString
name
;
switch
(
menuType
)
{
...
...
@@ -1370,8 +1332,6 @@ void UMLListView::init()
m_datatypeFolder
->
setOpen
(
false
);
//setup misc.
delete
m_menu
;
m_menu
=
0
;
m_bStartedCut
=
m_bStartedCopy
=
false
;
m_bCreatingChildObject
=
false
;
m_bRenameInProgress
=
false
;
...
...
@@ -1997,6 +1957,21 @@ void UMLListView::focusOutEvent(QFocusEvent * fe)
QTreeWidget
::
focusOutEvent
(
fe
);
}
void
UMLListView
::
contextMenuEvent
(
QContextMenuEvent
*
me
)
{
// Get the UMLListViewItem at the point where the mouse pointer was pressed
UMLListViewItem
*
item
=
static_cast
<
UMLListViewItem
*>
(
itemAt
(
me
->
pos
()));
if
(
item
)
{
const
UMLListViewItem
::
ListViewType
type
=
item
->
type
();
ListPopupMenu
*
popup
=
new
ListPopupMenu
(
this
,
type
,
item
->
umlObject
());
QAction
*
triggered
=
popup
->
exec
(
me
->
globalPos
());
slotMenuSelection
(
triggered
);
me
->
accept
();
}
QTreeWidget
::
contextMenuEvent
(
me
);
}
/**
* Determines the root listview type of the given UMLListViewItem.
* Starts at the given item, compares it against each of the
...
...
umbrello/umllistview.h
View file @
5dc8ee09
...
...
@@ -120,13 +120,12 @@ public:
protected:
bool
event
(
QEvent
*
e
);
bool
eventFilter
(
QObject
*
o
,
QEvent
*
e
);
void
mouseReleaseEvent
(
QMouseEvent
*
me
);
void
mousePressEvent
(
QMouseEvent
*
me
);
void
mouseMoveEvent
(
QMouseEvent
*
me
);
void
mouseDoubleClickEvent
(
QMouseEvent
*
me
);
void
focusOutEvent
(
QFocusEvent
*
fe
);
void
contextMenuEvent
(
QContextMenuEvent
*
me
);
UMLDragData
*
getDragData
();
bool
acceptDrag
(
QDropEvent
*
event
)
const
;
...
...
@@ -161,7 +160,7 @@ public slots:
void
slotObjectChanged
();
void
popup
MenuSel
(
QAction
*
action
);
void
slot
MenuSel
ection
(
QAction
*
action
);
void
slotDropped
(
QDropEvent
*
de
,
UMLListViewItem
*
target
);
...
...
@@ -185,7 +184,6 @@ private:
UMLListViewItem
*
m_rv
;
///< root view (home)
UMLListViewItem
*
m_lv
[
Uml
::
ModelType
::
N_MODELTYPES
];
///< predefined list view roots
UMLListViewItem
*
m_datatypeFolder
;
ListPopupMenu
*
m_menu
;
UMLDoc
*
m_doc
;
bool
m_bStartedCut
;
bool
m_bStartedCopy
;
...
...
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