Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
8b117635
Commit
8b117635
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
all datafiles in _one_ list
parent
77c47f4d
No related branches found
No related tags found
1 merge request
!2359
Use same tree view with delegate for datafiles, samples, and instruments. Also move some code between GUI/View directories. Restore Py wrappers lost in previous MR.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/Model/Files/DatafilesQModel.cpp
+17
-29
17 additions, 29 deletions
GUI/Model/Files/DatafilesQModel.cpp
GUI/Model/Files/DatafilesQModel.h
+2
-2
2 additions, 2 deletions
GUI/Model/Files/DatafilesQModel.h
with
19 additions
and
31 deletions
GUI/Model/Files/DatafilesQModel.cpp
+
17
−
29
View file @
8b117635
...
...
@@ -23,8 +23,7 @@ DatafilesQModel::DatafilesQModel(QObject* parent, DatafilesSet* model)
:
QAbstractItemModel
(
parent
)
,
m_model
(
model
)
{
for
(
int
rank
:
{
1
,
2
})
m_items
[
rank
-
1
]
=
model
->
dfileItems
(
rank
);
m_items
=
model
->
dfileItems
();
}
bool
DatafilesQModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
...
...
@@ -40,10 +39,9 @@ bool DatafilesQModel::setData(const QModelIndex& index, const QVariant& value, i
void
DatafilesQModel
::
injectDatafileItem
(
DatafileItem
*
item
)
{
m_model
->
insertDatafileItem
(
item
);
const
int
rank
=
item
->
rank
();
const
int
rowOfItem
=
m_model
->
dfileItems
(
rank
).
indexOf
(
item
);
beginInsertRows
(
indexOfHeadline
(
rank
),
rowOfItem
,
rowOfItem
);
m_items
[
rank
-
1
]
=
m_model
->
dfileItems
(
rank
);
const
int
rowOfItem
=
m_model
->
dfileItems
().
indexOf
(
item
);
beginInsertRows
(
indexOfHeadline
(),
rowOfItem
,
rowOfItem
);
m_items
=
m_model
->
dfileItems
();
endInsertRows
();
}
...
...
@@ -52,26 +50,23 @@ void DatafilesQModel::removeDatafileItem(DatafileItem* item)
QModelIndex
index
=
indexForItem
(
item
);
if
(
!
index
.
isValid
())
return
;
const
int
rank
=
item
->
rank
();
const
int
rowOfItem
=
m_items
[
rank
-
1
].
indexOf
(
item
);
beginRemoveRows
(
indexOfHeadline
(
rank
),
rowOfItem
,
rowOfItem
);
m_items
[
rank
-
1
].
removeAll
(
item
);
const
int
rowOfItem
=
m_items
.
indexOf
(
item
);
beginRemoveRows
(
indexOfHeadline
(),
rowOfItem
,
rowOfItem
);
m_items
.
removeAll
(
item
);
m_model
->
removeDatafileItem
(
item
);
endRemoveRows
();
}
DatafileItem
*
DatafilesQModel
::
topMostItem
()
const
{
if
(
!
m_items
[
0
].
isEmpty
())
return
m_items
[
0
].
first
();
if
(
!
m_items
[
1
].
isEmpty
())
return
m_items
[
1
].
first
();
if
(
!
m_items
.
isEmpty
())
return
m_items
.
first
();
return
nullptr
;
}
QModelIndex
DatafilesQModel
::
indexOfHeadline
(
int
rank
)
const
QModelIndex
DatafilesQModel
::
indexOfHeadline
()
const
{
return
createIndex
(
rank
-
1
,
0
,
nullptr
);
return
createIndex
(
0
,
0
,
nullptr
);
}
QModelIndex
DatafilesQModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
...
...
@@ -82,9 +77,8 @@ QModelIndex DatafilesQModel::index(int row, int column, const QModelIndex& paren
if
(
!
parent
.
isValid
())
return
createIndex
(
row
,
column
,
nullptr
);
for
(
int
rank
:
{
1
,
2
})
if
(
parent
==
indexOfHeadline
(
rank
))
return
createIndex
(
row
,
column
,
m_items
[
rank
-
1
][
row
]);
if
(
parent
==
indexOfHeadline
())
return
createIndex
(
row
,
column
,
m_items
[
row
]);
return
{};
}
...
...
@@ -97,7 +91,7 @@ QModelIndex DatafilesQModel::parent(const QModelIndex& index) const
if
(
index
.
internalPointer
()
==
nullptr
)
// index is headline => no parent
return
{};
return
indexOfHeadline
(
itemForIndex
(
index
)
->
rank
()
);
return
indexOfHeadline
();
}
int
DatafilesQModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
...
...
@@ -111,9 +105,8 @@ int DatafilesQModel::rowCount(const QModelIndex& parent) const
return
2
;
// parent is a headline
for
(
int
rank
:
{
1
,
2
})
if
(
parent
==
indexOfHeadline
(
rank
))
return
m_items
[
rank
-
1
].
size
();
if
(
parent
==
indexOfHeadline
())
return
m_items
.
size
();
return
0
;
}
...
...
@@ -155,7 +148,6 @@ DatafileItem* DatafilesQModel::itemForIndex(const QModelIndex& index) const
{
if
(
!
index
.
isValid
())
return
nullptr
;
return
reinterpret_cast
<
DatafileItem
*>
(
index
.
internalPointer
());
}
...
...
@@ -163,11 +155,8 @@ QModelIndex DatafilesQModel::indexForItem(DatafileItem* item) const
{
if
(
item
==
nullptr
)
return
{};
const
int
rank
=
item
->
rank
();
if
(
auto
index
=
m_items
[
rank
-
1
].
indexOf
(
item
);
index
>=
0
)
if
(
auto
index
=
m_items
.
indexOf
(
item
);
index
>=
0
)
return
createIndex
(
index
,
0
,
item
);
return
{};
}
...
...
@@ -175,6 +164,5 @@ bool DatafilesQModel::isHeadline(const QModelIndex& index) const
{
if
(
!
index
.
isValid
())
return
false
;
return
index
.
internalPointer
()
==
nullptr
;
}
This diff is collapsed.
Click to expand it.
GUI/Model/Files/DatafilesQModel.h
+
2
−
2
View file @
8b117635
...
...
@@ -42,12 +42,12 @@ public:
DatafileItem
*
itemForIndex
(
const
QModelIndex
&
index
)
const
;
QModelIndex
indexForItem
(
DatafileItem
*
item
)
const
;
DatafileItem
*
topMostItem
()
const
;
//!< The topmost visible item. Can be null.
QModelIndex
indexOfHeadline
(
int
rank
)
const
;
QModelIndex
indexOfHeadline
()
const
;
bool
isHeadline
(
const
QModelIndex
&
index
)
const
;
private:
DatafilesSet
*
const
m_model
;
QVector
<
DatafileItem
*>
m_items
[
2
]
;
//< Items borrowed from model. Never delete the ptrs!
QVector
<
DatafileItem
*>
m_items
;
//< Items borrowed from model. Never delete the ptrs!
};
#endif // BORNAGAIN_GUI_MODEL_FILES_DATAFILESQMODEL_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment