Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
f271e7a7
Commit
f271e7a7
authored
Feb 14, 2021
by
Waqar Ahmed
Browse files
Simplify inner data store
parent
48f87e35
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/project/gitstatusmodel.cpp
View file @
f271e7a7
...
...
@@ -27,7 +27,6 @@ QModelIndex GitStatusModel::index(int row, int column, const QModelIndex &parent
}
}
return
createIndex
(
row
,
column
,
rootIndex
);
;
}
QModelIndex
GitStatusModel
::
parent
(
const
QModelIndex
&
child
)
const
...
...
@@ -46,15 +45,11 @@ int GitStatusModel::rowCount(const QModelIndex &parent) const
}
if
(
parent
.
internalId
()
==
Root
)
{
if
(
parent
.
row
()
==
Staged
)
{
return
m_staged
.
size
();
}
else
if
(
parent
.
row
()
==
Changed
)
{
return
m_changed
.
size
();
}
else
if
(
parent
.
row
()
==
Untrack
)
{
return
m_untracked
.
size
();
}
else
if
(
parent
.
row
()
==
Conflict
)
{
return
m_unmerge
.
size
();
if
(
parent
.
row
()
<
0
||
parent
.
row
()
>
3
)
{
return
0
;
}
return
m_nodes
[
parent
.
row
()].
size
();
}
return
0
;
}
...
...
@@ -92,7 +87,7 @@ QVariant GitStatusModel::data(const QModelIndex &index, int role) const
return
branchIcon
;
}
}
else
{
if
(
role
!=
Qt
::
DisplayRole
)
{
if
(
role
!=
Qt
::
DisplayRole
&&
role
!=
Qt
::
DecorationRole
)
{
return
{};
}
int
rootIndex
=
index
.
internalId
();
...
...
@@ -100,14 +95,9 @@ QVariant GitStatusModel::data(const QModelIndex &index, int role) const
return
QVariant
();
}
if
(
rootIndex
==
Staged
)
return
m_staged
.
at
(
row
).
file
;
if
(
rootIndex
==
Changed
)
return
m_changed
.
at
(
row
).
file
;
if
(
rootIndex
==
Conflict
)
return
m_unmerge
.
at
(
row
).
file
;
if
(
rootIndex
==
Untrack
)
return
m_untracked
.
at
(
row
).
file
;
if
(
role
==
Qt
::
DisplayRole
)
{
return
m_nodes
[
rootIndex
].
at
(
row
).
file
;
}
}
return
{};
...
...
@@ -118,27 +108,20 @@ void GitStatusModel::addItems(const QVector<GitUtils::StatusItem> &staged,
const
QVector
<
GitUtils
::
StatusItem
>
&
untracked
)
{
beginResetModel
();
m_
s
taged
=
staged
;
m_
c
hanged
=
changed
;
m_
unmerge
=
unmerge
;
m_
u
ntrack
ed
=
untracked
;
m_
nodes
[
S
taged
]
=
staged
;
m_
nodes
[
C
hanged
]
=
changed
;
m_
nodes
[
Conflict
]
=
unmerge
;
m_
nodes
[
U
ntrack
]
=
untracked
;
endResetModel
();
}
QVector
<
int
>
GitStatusModel
::
emptyRows
()
{
QVector
<
int
>
empty
;
if
(
m_staged
.
isEmpty
())
{
empty
.
append
(
Staged
);
}
if
(
m_untracked
.
isEmpty
())
{
empty
.
append
(
Untrack
);
}
if
(
m_unmerge
.
isEmpty
())
{
empty
.
append
(
Conflict
);
}
if
(
m_changed
.
isEmpty
())
{
empty
.
append
(
Changed
);
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
if
(
m_nodes
[
i
].
isEmpty
())
{
empty
.
append
(
i
);
}
}
return
empty
;
}
addons/project/gitstatusmodel.h
View file @
f271e7a7
...
...
@@ -10,13 +10,6 @@ class GitStatusModel : public QAbstractItemModel
public:
explicit
GitStatusModel
(
QObject
*
parent
);
// enum Status { M, A, U };
// struct Item {
// QString file;
// Status status;
// };
// QAbstractItemModel interface
public:
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
override
;
QModelIndex
parent
(
const
QModelIndex
&
child
)
const
override
;
...
...
@@ -31,10 +24,7 @@ public:
QVector
<
int
>
emptyRows
();
private:
QVector
<
GitUtils
::
StatusItem
>
m_staged
;
QVector
<
GitUtils
::
StatusItem
>
m_changed
;
QVector
<
GitUtils
::
StatusItem
>
m_unmerge
;
QVector
<
GitUtils
::
StatusItem
>
m_untracked
;
QVector
<
GitUtils
::
StatusItem
>
m_nodes
[
4
];
};
#endif // GITSTATUSMODEL_H
Write
Preview
Supports
Markdown
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