Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
aa008605
Commit
aa008605
authored
Aug 02, 2018
by
LEFEBVREJP email
Browse files
WIP: Adding checkbox state for selection/deselection of items.
parent
2e845f6c
Changes
4
Show whitespace changes
Inline
Side-by-side
radixwidgets/navigationitem.cc
View file @
aa008605
...
...
@@ -11,6 +11,7 @@ class NavigationItem::PImpl
NavigationItem
*
parent
=
nullptr
;
QList
<
NavigationItem
*>
children
;
QList
<
QVariant
>
data
;
bool
checked
=
false
;
~
PImpl
();
};
...
...
@@ -75,6 +76,10 @@ int NavigationItem::row() const
NavigationItem
*
NavigationItem
::
parentItem
()
{
return
p
->
parent
;
}
bool
NavigationItem
::
isChecked
()
const
{
return
p
->
checked
;
}
void
NavigationItem
::
setChecked
(
bool
checked
)
{
p
->
checked
=
checked
;
}
NavigationItem
*
NavigationItem
::
child
(
int
row
)
{
return
p
->
children
.
value
(
row
);
...
...
radixwidgets/navigationitem.hh
View file @
aa008605
...
...
@@ -21,6 +21,8 @@ class NavigationItem
void
setData
(
int
column
,
QVariant
value
);
int
row
()
const
;
NavigationItem
*
parentItem
();
bool
isChecked
()
const
;
void
setChecked
(
bool
checked
);
private:
class
PImpl
;
...
...
radixwidgets/navigationmodel.cc
View file @
aa008605
...
...
@@ -37,16 +37,30 @@ QVariant NavigationModel::data(const QModelIndex& index, int role) const
radix_tagged_line
(
"data("
<<
index
.
row
()
<<
", "
<<
index
.
column
()
<<
")"
);
if
(
!
index
.
isValid
())
return
QVariant
();
if
(
role
!=
Qt
::
DisplayRole
)
return
QVariant
();
NavigationItem
*
item
=
static_cast
<
NavigationItem
*>
(
index
.
internalPointer
());
if
(
Qt
::
CheckStateRole
==
role
&&
index
.
column
()
==
0
)
return
static_cast
<
int
>
(
item
->
isChecked
()
?
Qt
::
Checked
:
Qt
::
Unchecked
);
if
(
role
!=
Qt
::
DisplayRole
)
return
QVariant
();
return
item
->
data
(
index
.
column
());
}
bool
NavigationModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
{
if
(
Qt
::
CheckStateRole
==
role
)
{
NavigationItem
*
item
=
static_cast
<
NavigationItem
*>
(
index
.
internalPointer
());
item
->
setChecked
(
value
.
toBool
());
// signal selection/deselection
if
(
item
->
isChecked
())
emit
itemChecked
(
index
);
else
emit
itemUnChecked
(
index
);
return
true
;
}
return
false
;
}
...
...
@@ -54,7 +68,10 @@ Qt::ItemFlags NavigationModel::flags(const QModelIndex& index) const
{
if
(
!
index
.
isValid
())
return
QAbstractItemModel
::
flags
(
index
);
return
QAbstractItemModel
::
flags
(
index
);
Qt
::
ItemFlags
flags
=
Qt
::
ItemIsEnabled
|
Qt
::
ItemIsSelectable
;
if
(
index
.
column
()
==
0
)
flags
|=
Qt
::
ItemIsUserCheckable
;
return
flags
;
}
QVariant
NavigationModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
...
...
radixwidgets/navigationmodel.hh
View file @
aa008605
...
...
@@ -25,6 +25,10 @@ class NavigationModel : public QAbstractItemModel
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
signals:
void
itemChecked
(
const
QModelIndex
&
index
);
void
itemUnChecked
(
const
QModelIndex
&
index
);
private:
class
PImpl
;
std
::
unique_ptr
<
PImpl
,
void
(
*
)(
PImpl
*
)
>
p
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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