Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Datovka projects
mobile Datovka
Commits
7ba14443
Commit
7ba14443
authored
Oct 16, 2017
by
Karel Slaný
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added DataboxListModel::removeEntry().
parent
f21c1d31
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
37 deletions
+102
-37
src/main.cpp
src/main.cpp
+1
-0
src/models/databoxmodel.cpp
src/models/databoxmodel.cpp
+71
-35
src/models/databoxmodel.h
src/models/databoxmodel.h
+30
-2
No files found.
src/main.cpp
View file @
7ba14443
...
...
@@ -294,6 +294,7 @@ int main(int argc, char *argv[])
/* Register types into QML. */
AccountListModel
::
declareQML
();
DataboxListModel
::
declareQML
();
DataboxModelEntry
::
declareQML
();
Dialogues
::
declareQML
();
FileListModel
::
declareQML
();
InteractionFilesystem
::
declareQML
();
...
...
src/models/databoxmodel.cpp
View file @
7ba14443
...
...
@@ -171,22 +171,22 @@ void DataboxListModel::declareQML(void)
DataboxListModel
::
DataboxListModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
),
m_
data
box
e
s
(),
m_
selected
()
m_box
Id
s
(),
m_
entries
()
{
}
DataboxListModel
::
DataboxListModel
(
const
DataboxListModel
&
model
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
),
m_
data
box
e
s
(
model
.
m_
data
box
e
s
),
m_
selected
(
model
.
m_
selected
)
m_box
Id
s
(
model
.
m_box
Id
s
),
m_
entries
(
model
.
m_
entries
)
{
}
int
DataboxListModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
return
!
parent
.
isValid
()
?
m_
data
box
e
s
.
size
()
:
0
;
return
!
parent
.
isValid
()
?
m_box
Id
s
.
size
()
:
0
;
}
QHash
<
int
,
QByteArray
>
DataboxListModel
::
roleNames
(
void
)
const
...
...
@@ -207,36 +207,37 @@ QHash<int, QByteArray> DataboxListModel::roleNames(void) const
QVariant
DataboxListModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
((
index
.
row
()
<
0
)
||
(
index
.
row
()
>=
m_
data
box
e
s
.
size
()))
{
if
((
index
.
row
()
<
0
)
||
(
index
.
row
()
>=
m_box
Id
s
.
size
()))
{
return
QVariant
();
}
const
DataboxModelEntry
&
databox
(
m_databoxes
.
at
(
index
.
row
()));
const
QString
&
boxId
(
m_boxIds
.
at
(
index
.
row
()));
const
DataboxModelEntry
&
entry
(
m_entries
[
boxId
].
entry
);
switch
(
role
)
{
case
ROLE_DB_ID
:
return
databox
.
dbID
();
return
entry
.
dbID
();
break
;
case
ROLE_DB_TYPE
:
return
databox
.
dbType
();
return
entry
.
dbType
();
break
;
case
ROLE_DB_NAME
:
return
databox
.
dbName
();
return
entry
.
dbName
();
break
;
case
ROLE_DB_ADDRESS
:
return
databox
.
dbAddress
();
return
entry
.
dbAddress
();
break
;
case
ROLE_DB_IC
:
return
databox
.
dbIC
();
return
entry
.
dbIC
();
break
;
case
ROLE_DB_EFFECTIVE_OVM
:
return
databox
.
dbEffectiveOVM
();
return
entry
.
dbEffectiveOVM
();
break
;
case
ROLE_DB_SEND_OPTION
:
return
databox
.
dbSendOptions
();
return
entry
.
dbSendOptions
();
break
;
case
ROLE_DB_SELECTED
:
return
m_
selected
.
at
(
index
.
row
())
;
return
m_
entries
[
boxId
].
selected
;
break
;
default:
/* Do nothing. */
...
...
@@ -248,13 +249,23 @@ QVariant DataboxListModel::data(const QModelIndex &index, int role) const
bool
DataboxListModel
::
addEntry
(
const
DataboxModelEntry
&
entry
)
{
if
(
Q_UNLIKELY
(
entry
.
dbID
().
isEmpty
()))
{
qDebug
(
"%s"
,
"BBB001"
);
const
QString
key
(
entry
.
dbID
());
if
(
Q_UNLIKELY
(
key
.
isEmpty
()))
{
qDebug
(
"%s"
,
"BBB002"
);
return
false
;
}
QMap
<
QString
,
InternalEntry
>::
const_iterator
it
=
m_entries
.
find
(
key
);
if
(
it
!=
m_entries
.
end
())
{
return
false
;
}
beginInsertRows
(
QModelIndex
(),
rowCount
(),
rowCount
());
m_
data
box
e
s
.
append
(
e
ntr
y
);
m_
selected
.
append
(
false
);
m_box
Id
s
.
append
(
k
ey
);
m_
entries
[
key
]
=
InternalEntry
(
entry
,
false
);
endInsertRows
();
return
true
;
...
...
@@ -270,20 +281,39 @@ bool DataboxListModel::addEntry(const QVariant &entryVariant)
return
addEntry
(
*
entry
);
}
DataboxModelEntry
*
DataboxListModel
::
e
ntry
(
const
QString
&
boxId
)
const
bool
DataboxListModel
::
removeE
ntry
(
const
QString
&
boxId
)
{
if
(
Q_UNLIKELY
(
boxId
.
isEmpty
()))
{
Q_ASSERT
(
0
);
return
new
(
std
::
nothrow
)
DataboxModelEntry
;
return
false
;
}
QMap
<
QString
,
InternalEntry
>::
const_iterator
it
=
m_entries
.
find
(
boxId
);
if
(
it
==
m_entries
.
end
())
{
return
false
;
}
foreach
(
const
DataboxModelEntry
&
entry
,
m_databoxes
)
{
if
(
entry
.
dbID
()
==
boxId
)
{
return
new
(
std
::
nothrow
)
DataboxModelEntry
(
entry
);
for
(
int
r
=
(
m_boxIds
.
size
()
-
1
);
r
>=
0
;
--
r
)
{
if
(
m_boxIds
.
at
(
r
)
==
boxId
)
{
beginRemoveRows
(
QModelIndex
(),
r
,
r
);
m_boxIds
.
removeAt
(
r
);
endRemoveRows
();
}
}
return
new
(
std
::
nothrow
)
DataboxModelEntry
;
m_entries
.
remove
(
boxId
);
return
true
;
}
DataboxModelEntry
*
DataboxListModel
::
entry
(
const
QString
&
boxId
)
const
{
if
(
Q_UNLIKELY
(
boxId
.
isEmpty
()))
{
Q_ASSERT
(
0
);
return
new
(
std
::
nothrow
)
DataboxModelEntry
;
}
return
new
(
std
::
nothrow
)
DataboxModelEntry
(
m_entries
.
value
(
boxId
,
InternalEntry
(
DataboxModelEntry
(),
false
)).
entry
);
}
bool
DataboxListModel
::
selectEntry
(
const
QString
&
boxId
,
bool
selected
)
...
...
@@ -292,9 +322,14 @@ bool DataboxListModel::selectEntry(const QString &boxId, bool selected)
return
false
;
}
for
(
int
i
=
0
;
i
<
m_databoxes
.
size
();
++
i
)
{
if
(
boxId
==
m_databoxes
.
at
(
i
).
dbID
())
{
m_selected
[
i
]
=
selected
;
QMap
<
QString
,
InternalEntry
>::
iterator
it
=
m_entries
.
find
(
boxId
);
if
(
it
==
m_entries
.
end
())
{
return
false
;
}
for
(
int
i
=
0
;
i
<
m_boxIds
.
size
();
++
i
)
{
if
(
boxId
==
m_boxIds
.
at
(
i
))
{
it
->
selected
=
selected
;
emit
dataChanged
(
QAbstractListModel
::
index
(
i
,
0
),
QAbstractListModel
::
index
(
i
,
0
));
...
...
@@ -317,19 +352,20 @@ int DataboxListModel::setQuery(QSqlQuery &query, const QString &dbId,
beginResetModel
();
if
(
!
isAppend
)
{
m_
data
box
e
s
.
clear
();
m_
selected
.
clear
();
m_box
Id
s
.
clear
();
m_
entries
.
clear
();
}
query
.
first
();
while
(
query
.
isActive
()
&&
query
.
isValid
())
{
if
(
dbId
!=
query
.
value
(
0
).
toString
())
{
// some model items are not available in local database
m_databoxes
.
append
(
DataboxModelEntry
(
DataboxModelEntry
entry
(
query
.
value
(
0
).
toString
(),
QString
(),
query
.
value
(
1
).
toString
(),
query
.
value
(
2
).
toString
(),
QString
(),
QString
(),
QString
()));
m_selected
.
append
(
false
);
QString
(),
QString
(),
QString
());
m_boxIds
.
append
(
entry
.
dbID
());
m_entries
[
entry
.
dbID
()]
=
InternalEntry
(
entry
,
false
);
databoxCnt
++
;
}
query
.
next
();
...
...
@@ -348,8 +384,8 @@ Qt::ItemFlags DataboxListModel::flags(const QModelIndex &index) const
void
DataboxListModel
::
clearAll
(
void
)
{
beginResetModel
();
m_
data
box
e
s
.
clear
();
m_
selected
.
clear
();
m_box
Id
s
.
clear
();
m_
entries
.
clear
();
endResetModel
();
}
...
...
src/models/databoxmodel.h
View file @
7ba14443
...
...
@@ -210,6 +210,15 @@ public:
Q_INVOKABLE
bool
addEntry
(
const
QVariant
&
entryVariant
);
/*!
* @brief Remove model entry.
*
* @param[in] boxId Data box identifier of the removed box entry.
* @return True if entry was really removed.
*/
Q_INVOKABLE
bool
removeEntry
(
const
QString
&
boxId
);
/*!
* @brief Return entry at given row.
*
...
...
@@ -270,8 +279,27 @@ public:
DataboxListModel
*
fromVariant
(
const
QVariant
&
modelVariant
);
private:
QList
<
DataboxModelEntry
>
m_databoxes
;
/*!< List of box entries. */
QList
<
bool
>
m_selected
;
/*!< Holds information whether entry is selected. */
/*!
* @brief Convenience structure.
*/
class
InternalEntry
{
public:
InternalEntry
(
void
)
:
entry
(),
selected
(
false
)
{
}
InternalEntry
(
const
DataboxModelEntry
&
e
,
bool
s
)
:
entry
(
e
),
selected
(
s
)
{
}
DataboxModelEntry
entry
;
bool
selected
;
};
QList
<
QString
>
m_boxIds
;
/*!< List of box identifiers (map keys). */
QMap
<
QString
,
InternalEntry
>
m_entries
;
/*!< Data box entries. */
};
/* QML passes its arguments via QVariant. */
...
...
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