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
f622859b
Commit
f622859b
authored
Mar 13, 2018
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for insert/append of multiple objects at a time
For much better performance
parent
fbcb38e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
6 deletions
+39
-6
QmlObjectListModel.cc
src/QmlControls/QmlObjectListModel.cc
+31
-0
QmlObjectListModel.h
src/QmlControls/QmlObjectListModel.h
+8
-6
No files found.
src/QmlControls/QmlObjectListModel.cc
View file @
f622859b
...
@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object)
...
@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object)
setDirty
(
true
);
setDirty
(
true
);
}
}
void
QmlObjectListModel
::
insert
(
int
i
,
QList
<
QObject
*>
objects
)
{
if
(
i
<
0
||
i
>
_objectList
.
count
())
{
qWarning
()
<<
"Invalid index index:count"
<<
i
<<
_objectList
.
count
();
}
int
j
=
i
;
foreach
(
QObject
*
object
,
objects
)
{
QQmlEngine
::
setObjectOwnership
(
object
,
QQmlEngine
::
CppOwnership
);
// Look for a dirtyChanged signal on the object
if
(
object
->
metaObject
()
->
indexOfSignal
(
QMetaObject
::
normalizedSignature
(
"dirtyChanged(bool)"
))
!=
-
1
)
{
if
(
!
_skipDirtyFirstItem
||
j
!=
0
)
{
QObject
::
connect
(
object
,
SIGNAL
(
dirtyChanged
(
bool
)),
this
,
SLOT
(
_childDirtyChanged
(
bool
)));
}
}
j
++
;
_objectList
.
insert
(
i
,
object
);
}
insertRows
(
i
,
objects
.
count
());
setDirty
(
true
);
}
void
QmlObjectListModel
::
append
(
QObject
*
object
)
void
QmlObjectListModel
::
append
(
QObject
*
object
)
{
{
insert
(
_objectList
.
count
(),
object
);
insert
(
_objectList
.
count
(),
object
);
}
}
void
QmlObjectListModel
::
append
(
QList
<
QObject
*>
objects
)
{
insert
(
_objectList
.
count
(),
objects
);
}
QObjectList
QmlObjectListModel
::
swapObjectList
(
const
QObjectList
&
newlist
)
QObjectList
QmlObjectListModel
::
swapObjectList
(
const
QObjectList
&
newlist
)
{
{
QObjectList
oldlist
(
_objectList
);
QObjectList
oldlist
(
_objectList
);
...
...
src/QmlControls/QmlObjectListModel.h
View file @
f622859b
...
@@ -37,11 +37,13 @@ public:
...
@@ -37,11 +37,13 @@ public:
void
setDirty
(
bool
dirty
);
void
setDirty
(
bool
dirty
);
void
append
(
QObject
*
object
);
void
append
(
QObject
*
object
);
void
append
(
QList
<
QObject
*>
objects
);
QObjectList
swapObjectList
(
const
QObjectList
&
newlist
);
QObjectList
swapObjectList
(
const
QObjectList
&
newlist
);
void
clear
(
void
);
void
clear
(
void
);
QObject
*
removeAt
(
int
i
);
QObject
*
removeAt
(
int
i
);
QObject
*
removeOne
(
QObject
*
object
)
{
return
removeAt
(
indexOf
(
object
));
}
QObject
*
removeOne
(
QObject
*
object
)
{
return
removeAt
(
indexOf
(
object
));
}
void
insert
(
int
i
,
QObject
*
object
);
void
insert
(
int
i
,
QObject
*
object
);
void
insert
(
int
i
,
QList
<
QObject
*>
objects
);
QObject
*
operator
[](
int
i
);
QObject
*
operator
[](
int
i
);
const
QObject
*
operator
[](
int
i
)
const
;
const
QObject
*
operator
[](
int
i
)
const
;
bool
contains
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
)
!=
-
1
;
}
bool
contains
(
QObject
*
object
)
{
return
_objectList
.
indexOf
(
object
)
!=
-
1
;
}
...
@@ -63,12 +65,12 @@ private slots:
...
@@ -63,12 +65,12 @@ private slots:
private:
private:
// Overrides from QAbstractListModel
// Overrides from QAbstractListModel
virtual
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
virtual
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
virtual
QHash
<
int
,
QByteArray
>
roleNames
(
void
)
const
;
QHash
<
int
,
QByteArray
>
roleNames
(
void
)
const
override
;
virtual
bool
insertRows
(
int
position
,
int
rows
,
const
QModelIndex
&
index
=
QModelIndex
())
;
bool
insertRows
(
int
position
,
int
rows
,
const
QModelIndex
&
index
=
QModelIndex
())
override
;
virtual
bool
removeRows
(
int
position
,
int
rows
,
const
QModelIndex
&
index
=
QModelIndex
())
;
bool
removeRows
(
int
position
,
int
rows
,
const
QModelIndex
&
index
=
QModelIndex
())
override
;
virtual
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
=
Qt
::
EditRole
)
;
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
=
Qt
::
EditRole
)
override
;
private:
private:
QList
<
QObject
*>
_objectList
;
QList
<
QObject
*>
_objectList
;
...
...
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