Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
ea213069
Commit
ea213069
authored
Apr 29, 2020
by
Aleksey Kontsevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to move/reorder objects within QmlObjectListModel
parent
0f32617d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
QmlObjectListModel.cc
src/QmlControls/QmlObjectListModel.cc
+16
-0
QmlObjectListModel.h
src/QmlControls/QmlObjectListModel.h
+3
-0
No files found.
src/QmlControls/QmlObjectListModel.cc
View file @
ea213069
...
...
@@ -125,6 +125,22 @@ bool QmlObjectListModel::removeRows(int position, int rows, const QModelIndex& p
return
true
;
}
void
QmlObjectListModel
::
move
(
int
from
,
int
to
)
{
if
(
0
<=
from
&&
from
<
count
()
&&
0
<=
to
&&
to
<
count
()
&&
from
!=
to
)
{
// Workaround to allow move item to the bottom. Done according to
// beginMoveRows() documentation and implementation specificity:
// https://doc.qt.io/qt-5/qabstractitemmodel.html#beginMoveRows
// (see 3rd picture explanation there)
if
(
from
==
to
-
1
)
{
to
=
from
++
;
}
beginMoveRows
(
QModelIndex
(),
from
,
from
,
QModelIndex
(),
to
);
_objectList
.
move
(
from
,
to
);
endMoveRows
();
}
}
QObject
*
QmlObjectListModel
::
operator
[](
int
index
)
{
if
(
index
<
0
||
index
>=
_objectList
.
count
())
{
...
...
src/QmlControls/QmlObjectListModel.h
View file @
ea213069
...
...
@@ -46,6 +46,9 @@ public:
bool
contains
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
)
!=
-
1
;
}
int
indexOf
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
);
}
/// Moves an item to a new position
void
move
(
int
from
,
int
to
);
QObject
*
operator
[]
(
int
i
);
const
QObject
*
operator
[]
(
int
i
)
const
;
template
<
class
T
>
T
value
(
int
index
)
{
return
qobject_cast
<
T
>
(
_objectList
[
index
]);
}
...
...
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