Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Ben Boeckel
SMTK
Commits
4b80fa53
Commit
4b80fa53
authored
Sep 08, 2017
by
Alvaro Sanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix listView update issue in qtCheckItemComboBox.
(cherry-picked from
6708614d
)
parent
76bef1e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
69 deletions
+42
-69
smtk/extension/qt/qtCheckItemComboBox.cxx
smtk/extension/qt/qtCheckItemComboBox.cxx
+31
-55
smtk/extension/qt/qtCheckItemComboBox.h
smtk/extension/qt/qtCheckItemComboBox.h
+11
-14
No files found.
smtk/extension/qt/qtCheckItemComboBox.cxx
View file @
4b80fa53
...
...
@@ -63,7 +63,6 @@ void qtCheckItemComboBox::init()
{
this
->
m_displayItem
=
new
QStandardItem
;
this
->
m_displayItem
->
setFlags
(
Qt
::
ItemIsEnabled
);
this
->
m_displayItem
->
setCheckable
(
false
);
this
->
m_displayItem
->
setText
(
"0 "
+
m_displayTextExt
);
QStandardItemModel
*
itemModel
=
qobject_cast
<
QStandardItemModel
*>
(
this
->
model
());
if
(
itemModel
)
...
...
@@ -93,7 +92,15 @@ void qtCheckItemComboBox::updateText()
:
QString
::
number
(
numSel
)
+
" "
+
m_displayTextExt
;
this
->
m_displayItem
->
setText
(
displayText
);
this
->
view
()
->
model
()
->
setData
(
this
->
view
()
->
model
()
->
index
(
0
,
0
),
displayText
,
Qt
::
DisplayRole
);
this
->
view
()
->
update
();
// For the item list, all the painting operations take place in the viewport
// (since it is a QAbstractItemView), so use its update() to reflect any changes.
// http://doc.qt.io/qt-5/qabstractitemview.html#update
this
->
view
()
->
viewport
()
->
update
();
// Additionally, update the baseclass to reflect the changes in the
// actual combobox (selected item name and button).
this
->
update
();
}
void
qtCheckItemComboBox
::
hidePopup
()
...
...
@@ -109,6 +116,27 @@ void qtCheckItemComboBox::showPopup()
this
->
QComboBox
::
showPopup
();
}
bool
qtCheckItemComboBox
::
eventFilter
(
QObject
*
editor
,
QEvent
*
evt
)
{
if
(
evt
->
type
()
==
QEvent
::
MouseButtonRelease
)
{
const
int
index
=
view
()
->
currentIndex
().
row
();
auto
itemModel
=
qobject_cast
<
QStandardItemModel
*>
(
this
->
model
());
QStandardItem
*
item
=
itemModel
->
item
(
index
);
if
(
item
->
isCheckable
())
{
const
auto
newState
=
itemData
(
index
,
Qt
::
CheckStateRole
)
==
Qt
::
Checked
?
Qt
::
Unchecked
:
Qt
::
Checked
;
setItemData
(
index
,
newState
,
Qt
::
CheckStateRole
);
}
return
true
;
}
return
QObject
::
eventFilter
(
editor
,
evt
);
}
////////////////////////////////////////////////////////////////////////////////
qtModelEntityItemCombo
::
qtModelEntityItemCombo
(
qtModelEntityItem
*
entitem
,
QWidget
*
inParent
,
const
QString
&
displayExt
)
:
qtCheckItemComboBox
(
inParent
,
displayExt
)
...
...
@@ -195,7 +223,6 @@ void qtModelEntityItemCombo::init()
// this, SLOT(attributeFilterChanged(QStandardItem*)));
this
->
blockSignals
(
false
);
this
->
view
()
->
viewport
()
->
installEventFilter
(
this
);
// this->view()->setSelectionMode(QAbstractItemView::ExtendedSelection);
this
->
updateText
();
this
->
hidePopup
();
...
...
@@ -210,36 +237,10 @@ void qtModelEntityItemCombo::init()
void
qtModelEntityItemCombo
::
showPopup
()
{
this
->
setModel
(
new
QStandardItemModel
());
this
->
init
();
this
->
qtCheckItemComboBox
::
showPopup
();
}
bool
qtModelEntityItemCombo
::
eventFilter
(
QObject
*
editor
,
QEvent
*
evt
)
{
if
(
evt
->
type
()
==
QEvent
::
MouseButtonRelease
)
{
int
index
=
view
()
->
currentIndex
().
row
();
/*
// with the help of styles, check if checkbox rect contains 'pos'
QMouseEvent* e = dynamic_cast<QMouseEvent*>(evt);
QStyleOptionButton opt;
opt.rect = view()->visualRect(view()->currentIndex());
QRect r = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt);
if(r.contains(e->pos()))
{
*/
if
(
itemData
(
index
,
Qt
::
CheckStateRole
)
==
Qt
::
Checked
)
setItemData
(
index
,
Qt
::
Unchecked
,
Qt
::
CheckStateRole
);
else
setItemData
(
index
,
Qt
::
Checked
,
Qt
::
CheckStateRole
);
// }
return
true
;
}
return
QObject
::
eventFilter
(
editor
,
evt
);
}
void
qtModelEntityItemCombo
::
itemCheckChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
)
{
QStandardItemModel
*
itemModel
=
qobject_cast
<
QStandardItemModel
*>
(
this
->
model
());
...
...
@@ -297,6 +298,7 @@ void qtModelEntityItemCombo::itemCheckChanged(const QModelIndex& topLeft, const
}
}
////////////////////////////////////////////////////////////////////////////////
qtMeshItemCombo
::
qtMeshItemCombo
(
qtMeshItem
*
entitem
,
QWidget
*
inParent
,
const
QString
&
displayExt
)
:
qtCheckItemComboBox
(
inParent
,
displayExt
)
,
m_MeshItem
(
entitem
)
...
...
@@ -386,7 +388,6 @@ void qtMeshItemCombo::init()
// this, SLOT(attributeFilterChanged(QStandardItem*)));
this
->
blockSignals
(
false
);
this
->
view
()
->
viewport
()
->
installEventFilter
(
this
);
// this->view()->setSelectionMode(QAbstractItemView::ExtendedSelection);
this
->
updateText
();
this
->
hidePopup
();
...
...
@@ -405,31 +406,6 @@ void qtMeshItemCombo::showPopup()
this
->
qtCheckItemComboBox
::
showPopup
();
}
bool
qtMeshItemCombo
::
eventFilter
(
QObject
*
editor
,
QEvent
*
evt
)
{
if
(
evt
->
type
()
==
QEvent
::
MouseButtonRelease
)
{
int
index
=
view
()
->
currentIndex
().
row
();
/*
// with the help of styles, check if checkbox rect contains 'pos'
QMouseEvent* e = dynamic_cast<QMouseEvent*>(evt);
QStyleOptionButton opt;
opt.rect = view()->visualRect(view()->currentIndex());
QRect r = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt);
if(r.contains(e->pos()))
{
*/
if
(
itemData
(
index
,
Qt
::
CheckStateRole
)
==
Qt
::
Checked
)
setItemData
(
index
,
Qt
::
Unchecked
,
Qt
::
CheckStateRole
);
else
setItemData
(
index
,
Qt
::
Checked
,
Qt
::
CheckStateRole
);
// }
return
true
;
}
return
QObject
::
eventFilter
(
editor
,
evt
);
}
void
qtMeshItemCombo
::
itemCheckChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
)
{
QStandardItemModel
*
itemModel
=
qobject_cast
<
QStandardItemModel
*>
(
this
->
model
());
...
...
smtk/extension/qt/qtCheckItemComboBox.h
View file @
4b80fa53
...
...
@@ -33,8 +33,8 @@ class SMTKQTEXT_EXPORT qtCheckableComboItemDelegate : public QStyledItemDelegate
Q_OBJECT
public:
qtCheckableComboItemDelegate
(
QWidget
*
owner
);
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
override
;
};
//A sublcass of QComboBox to set text when hidePopup
...
...
@@ -43,11 +43,14 @@ class SMTKQTEXT_EXPORT qtCheckItemComboBox : public QComboBox
Q_OBJECT
public:
qtCheckItemComboBox
(
QWidget
*
parentW
,
const
QString
&
displayExt
);
virtual
void
hidePopup
();
virtual
void
showPopup
();
void
hidePopup
()
override
;
void
showPopup
()
override
;
virtual
void
init
();
virtual
void
updateText
();
protected:
bool
eventFilter
(
QObject
*
editor
,
QEvent
*
event
)
override
;
private:
QStandardItem
*
m_displayItem
;
QString
m_displayTextExt
;
...
...
@@ -59,15 +62,12 @@ class SMTKQTEXT_EXPORT qtModelEntityItemCombo : public qtCheckItemComboBox
Q_OBJECT
public:
qtModelEntityItemCombo
(
qtModelEntityItem
*
item
,
QWidget
*
parent
,
const
QString
&
displayExt
);
virtual
void
showPopup
();
virtual
void
init
();
void
showPopup
()
override
;
void
init
()
override
;
protected
slots
:
virtual
void
itemCheckChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
bottomRight
);
protected:
virtual
bool
eventFilter
(
QObject
*
editor
,
QEvent
*
event
);
private:
qtModelEntityItem
*
m_ModelEntityItem
;
};
...
...
@@ -78,15 +78,12 @@ class SMTKQTEXT_EXPORT qtMeshItemCombo : public qtCheckItemComboBox
Q_OBJECT
public:
qtMeshItemCombo
(
qtMeshItem
*
item
,
QWidget
*
parent
,
const
QString
&
displayExt
);
virtual
void
showPopup
();
virtual
void
init
();
void
showPopup
()
override
;
void
init
()
override
;
protected
slots
:
virtual
void
itemCheckChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
bottomRight
);
protected:
virtual
bool
eventFilter
(
QObject
*
editor
,
QEvent
*
event
);
private:
qtMeshItem
*
m_MeshItem
;
};
...
...
Write
Preview
Markdown
is supported
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