Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
ea213069
Commit
ea213069
authored
Apr 29, 2020
by
Aleksey Kontsevich
Browse files
Allow to move/reorder objects within QmlObjectListModel
parent
0f32617d
Changes
2
Hide whitespace changes
Inline
Side-by-side
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
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