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
c34499fa
Unverified
Commit
c34499fa
authored
May 02, 2020
by
Don Gagne
Committed by
GitHub
May 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8702 from airmap/object_list_move
Allow to move/reorder objects within QmlObjectListModel
parents
8151a6cd
ea213069
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 @
c34499fa
...
@@ -125,6 +125,22 @@ bool QmlObjectListModel::removeRows(int position, int rows, const QModelIndex& p
...
@@ -125,6 +125,22 @@ bool QmlObjectListModel::removeRows(int position, int rows, const QModelIndex& p
return
true
;
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
)
QObject
*
QmlObjectListModel
::
operator
[](
int
index
)
{
{
if
(
index
<
0
||
index
>=
_objectList
.
count
())
{
if
(
index
<
0
||
index
>=
_objectList
.
count
())
{
...
...
src/QmlControls/QmlObjectListModel.h
View file @
c34499fa
...
@@ -46,6 +46,9 @@ public:
...
@@ -46,6 +46,9 @@ public:
bool
contains
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
)
!=
-
1
;
}
bool
contains
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
)
!=
-
1
;
}
int
indexOf
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
);
}
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
);
QObject
*
operator
[]
(
int
i
);
const
QObject
*
operator
[]
(
int
i
)
const
;
const
QObject
*
operator
[]
(
int
i
)
const
;
template
<
class
T
>
T
value
(
int
index
)
{
return
qobject_cast
<
T
>
(
_objectList
[
index
]);
}
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