Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
b9490705
Commit
b9490705
authored
Aug 02, 2018
by
LEFEBVREJP email
Browse files
Reworked navigationmodel for ease of use with adding children. Still need action integration.
parent
aa008605
Pipeline
#14513
passed with stages
in 7 minutes and 33 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
radixwidgets/examples/radixnavigationwidget.cc
View file @
b9490705
...
...
@@ -10,15 +10,23 @@
#include <QGridLayout>
#include <QLabel>
#include <limits>
#include "radixwidgets/navigationitem.hh"
#include "radixwidgets/navigationmodel.hh"
#include "radixwidgets/navigationwidget.hh"
using
namespace
radix
;
MainWindow
::
MainWindow
(
QWidget
*
parent
)
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
)
{
setGeometry
(
400
,
250
,
542
,
390
);
mWidget
=
new
radix
::
NavigationWidget
(
this
);
mWidget
=
new
NavigationWidget
(
this
);
NavigationModel
*
model
=
mWidget
->
navigationModel
();
NavigationItem
*
root
=
model
->
rootItem
();
auto
hello
=
model
->
addItem
(
"Hello"
,
root
);
auto
world
=
model
->
addItem
(
"World"
,
root
);
auto
hidden_beneath
=
model
->
addItem
(
"Hidden beneath"
,
world
);
setCentralWidget
(
mWidget
);
}
...
...
@@ -28,7 +36,7 @@ MainWindow::~MainWindow() {}
/******************************** MAIN PROGRAM ********************************/
/******************************************************************************/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
QApplication
app
(
argc
,
argv
);
MainWindow
mainWindow
;
...
...
radixwidgets/navigationitem.cc
View file @
b9490705
...
...
@@ -48,7 +48,16 @@ void NavigationItem::addChild(NavigationItem *child)
int
NavigationItem
::
childCount
()
const
{
return
p
->
children
.
size
();
}
int
NavigationItem
::
columnCount
()
const
{
return
p
->
data
.
size
();
}
int
NavigationItem
::
columnCount
()
const
{
// recursively find the largest number of columns from children
int
count
=
p
->
data
.
size
();
for
(
int
ci
=
0
;
ci
<
p
->
children
.
size
();
++
ci
)
{
count
=
std
::
max
(
count
,
p
->
children
[
ci
]
->
columnCount
());
}
return
count
;
}
QVariant
NavigationItem
::
data
(
int
column
)
const
{
...
...
radixwidgets/navigationmodel.cc
View file @
b9490705
...
...
@@ -23,18 +23,11 @@ NavigationModel::NavigationModel(QObject* parent)
:
QAbstractItemModel
(
parent
)
,
p
(
new
PImpl
(),
[](
PImpl
*
impl
)
{
delete
impl
;
})
{
radix_tagged_line
(
"Navigation Model"
);
p
->
root
=
new
NavigationItem
({
"Header 1"
,
"Header 2"
});
p
->
root
->
addChild
(
new
NavigationItem
(
"Hello"
,
p
->
root
));
NavigationItem
*
world
=
new
NavigationItem
(
"World"
,
p
->
root
);
p
->
root
->
addChild
(
world
);
NavigationItem
*
child
=
new
NavigationItem
(
"My name is edward"
,
world
);
world
->
addChild
(
child
);
p
->
root
=
new
NavigationItem
();
}
QVariant
NavigationModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
radix_tagged_line
(
"data("
<<
index
.
row
()
<<
", "
<<
index
.
column
()
<<
")"
);
if
(
!
index
.
isValid
())
return
QVariant
();
NavigationItem
*
item
=
static_cast
<
NavigationItem
*>
(
index
.
internalPointer
());
...
...
@@ -86,7 +79,6 @@ QVariant NavigationModel::headerData(int section, Qt::Orientation orientation,
QModelIndex
NavigationModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
radix_tagged_line
(
"index("
<<
row
<<
","
<<
column
<<
")"
);
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
NavigationItem
*
parentItem
;
...
...
@@ -105,7 +97,6 @@ QModelIndex NavigationModel::index(int row, int column,
QModelIndex
NavigationModel
::
parent
(
const
QModelIndex
&
index
)
const
{
radix_tagged_line
(
"parent("
<<
index
.
row
()
<<
","
<<
index
.
column
()
<<
")"
);
if
(
!
index
.
isValid
())
return
QModelIndex
();
NavigationItem
*
childItem
=
...
...
@@ -119,8 +110,6 @@ QModelIndex NavigationModel::parent(const QModelIndex& index) const
int
NavigationModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
radix_tagged_line
(
"rowCount("
<<
parent
.
row
()
<<
","
<<
parent
.
column
()
<<
")"
);
NavigationItem
*
parentItem
;
if
(
parent
.
column
()
>
0
)
return
0
;
...
...
@@ -134,8 +123,6 @@ int NavigationModel::rowCount(const QModelIndex& parent) const
int
NavigationModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
{
radix_tagged_line
(
"columnCount("
<<
parent
.
row
()
<<
","
<<
parent
.
column
()
<<
")"
);
if
(
parent
.
isValid
())
return
static_cast
<
NavigationItem
*>
(
parent
.
internalPointer
())
->
columnCount
();
...
...
@@ -143,4 +130,15 @@ int NavigationModel::columnCount(const QModelIndex& parent) const
return
p
->
root
->
columnCount
();
}
NavigationItem
*
NavigationModel
::
rootItem
()
{
return
p
->
root
;
}
NavigationItem
*
NavigationModel
::
addItem
(
QVariant
value
,
NavigationItem
*
parent
)
{
beginResetModel
();
NavigationItem
*
newItem
=
new
NavigationItem
(
value
,
parent
);
parent
->
addChild
(
newItem
);
endResetModel
();
return
newItem
;
}
}
// namespace radix
radixwidgets/navigationmodel.hh
View file @
b9490705
...
...
@@ -7,6 +7,9 @@
namespace
radix
{
// Forward declaration
class
NavigationItem
;
class
NavigationModel
:
public
QAbstractItemModel
{
Q_OBJECT
...
...
@@ -24,6 +27,8 @@ class NavigationModel : public QAbstractItemModel
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
NavigationItem
*
rootItem
();
NavigationItem
*
addItem
(
QVariant
value
,
NavigationItem
*
parent
);
signals:
void
itemChecked
(
const
QModelIndex
&
index
);
...
...
radixwidgets/navigationwidget.cc
View file @
b9490705
...
...
@@ -89,6 +89,16 @@ NavigationWidget::NavigationWidget(QWidget* parent)
initLayout
();
}
NavigationModel
*
NavigationWidget
::
navigationModel
()
{
return
p
->
model
;
}
void
NavigationWidget
::
contextMenuRequested
(
QPoint
point
)
{
radix_tagged_line
(
"contextMenuRequested()"
);
QModelIndex
index
=
p
->
view
->
indexAt
(
point
);
QMenu
m
;
m
.
exec
(
p
->
view
->
viewport
()
->
mapToGlobal
(
point
));
}
void
NavigationWidget
::
initLayout
()
{
auto
vlayout
=
new
QVBoxLayout
(
this
);
...
...
@@ -137,6 +147,8 @@ void NavigationWidget::initMembers()
SLOT
(
filterModel
(
QString
)));
connect
(
p
->
view
,
SIGNAL
(
doubleClicked
(
QModelIndex
)),
this
,
SLOT
(
itemDoubleClicked
(
QModelIndex
)));
connect
(
p
->
view
,
SIGNAL
(
customContextMenuRequested
(
QPoint
)),
this
,
SLOT
(
contextMenuRequested
(
QPoint
)));
}
void
NavigationWidget
::
filterModel
(
const
QString
&
pattern
)
{
...
...
radixwidgets/navigationwidget.hh
View file @
b9490705
...
...
@@ -15,7 +15,9 @@ QT_END_NAMESPACE
namespace
radix
{
// Forward declaration
class
NavigationItem
;
class
NavigationModel
;
class
NavigationItemSortFilterProxyModel
:
public
QSortFilterProxyModel
{
...
...
@@ -46,16 +48,18 @@ class NavigationWidget : public QWidget
void
collapse
(
QStandardItem
*
item
);
void
expand
(
QStandardItem
*
item
);
NavigationModel
*
navigationModel
();
QTreeView
*
navigationTree
()
const
;
private
slots
:
void
contextMenuRequested
(
QPoint
);
public
slots
:
void
filterModel
(
const
QString
&
pattern
);
void
itemDoubleClicked
(
QModelIndex
index
);
signals:
void
item
Activated
(
NavigationItem
*
item
);
void
itemChecked
(
const
QModelIndex
&
index
);
void
item
Unchecked
(
const
QModelIndex
&
index
);
private:
void
initLayout
();
...
...
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