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
6fd7a6e4
Commit
6fd7a6e4
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
a05d40bc
No related branches found
Branches containing commit
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
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GUI/Model/Files/DatafilesQModel.cpp
+11
-88
11 additions, 88 deletions
GUI/Model/Files/DatafilesQModel.cpp
GUI/Model/Files/DatafilesQModel.h
+5
-11
5 additions, 11 deletions
GUI/Model/Files/DatafilesQModel.h
GUI/Model/Files/DatafilesSet.h
+1
-0
1 addition, 0 deletions
GUI/Model/Files/DatafilesSet.h
with
17 additions
and
99 deletions
GUI/Model/Files/DatafilesQModel.cpp
+
11
−
88
View file @
6fd7a6e4
...
...
@@ -17,25 +17,15 @@
#include
"GUI/Model/Files/DatafilesSet.h"
DatafilesQModel
::
DatafilesQModel
(
QObject
*
parent
,
DatafilesSet
*
model
)
:
QAbstract
Item
Model
(
parent
)
:
QAbstract
List
Model
(
parent
)
,
m_model
(
model
)
{
}
bool
DatafilesQModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
{
if
(
role
==
Qt
::
EditRole
&&
index
.
isValid
()
&&
index
.
column
()
==
0
)
{
itemForIndex
(
index
)
->
setDatafileItemName
(
value
.
toString
());
emit
dataChanged
(
index
,
index
);
return
true
;
}
return
false
;
}
void
DatafilesQModel
::
injectDatafileItem
(
DatafileItem
*
item
)
{
const
int
row
=
m_model
->
size
();
beginInsertRows
(
indexOfHeadline
()
,
row
,
row
);
beginInsertRows
(
{}
,
row
,
row
);
m_model
->
appendDatafileItem
(
item
);
endInsertRows
();
}
...
...
@@ -43,7 +33,7 @@ void DatafilesQModel::injectDatafileItem(DatafileItem* item)
void
DatafilesQModel
::
removeDatafileItemAt
(
int
row
)
{
ASSERT
(
0
<=
row
&&
row
<
(
int
)
m_model
->
size
());
beginRemoveRows
(
indexOfHeadline
()
,
row
,
row
);
beginRemoveRows
(
{}
,
row
,
row
);
m_model
->
deleteDatafileItemAt
(
row
);
endRemoveRows
();
}
...
...
@@ -55,91 +45,31 @@ const DatafileItem* DatafilesQModel::topMostItem() const
return
nullptr
;
}
QModelIndex
DatafilesQModel
::
indexOfHeadline
()
const
{
return
createIndex
(
0
,
0
,
nullptr
);
}
QModelIndex
DatafilesQModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
{};
if
(
!
parent
.
isValid
())
return
createIndex
(
row
,
column
,
nullptr
);
if
(
parent
==
indexOfHeadline
())
return
createIndex
(
row
,
column
,
m_model
->
dfileItemAt
(
row
));
return
{};
}
QModelIndex
DatafilesQModel
::
parent
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
{};
if
(
index
.
internalPointer
()
==
nullptr
)
// index is headline => no parent
return
{};
return
indexOfHeadline
();
}
int
DatafilesQModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
int
DatafilesQModel
::
rowCount
(
const
QModelIndex
&
/*parent*/
)
const
{
return
1
;
}
int
DatafilesQModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
if
(
!
parent
.
isValid
())
return
1
;
// parent is a headline
if
(
parent
==
indexOfHeadline
())
return
m_model
->
size
();
return
0
;
return
m_model
->
size
();
}
QVariant
DatafilesQModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
isHeadline
(
index
)
)
if
(
!
index
.
isValid
()
||
index
.
row
()
>=
(
int
)
m_model
->
size
()
||
index
.
row
()
<
0
)
return
{};
auto
*
const
item
=
itemForIndex
(
index
);
if
(
role
==
Qt
::
ToolTipRole
)
return
{};
const
auto
*
item
=
itemForIndex
(
index
);
ASSERT
(
item
);
if
(
role
==
Qt
::
DisplayRole
)
return
item
->
realItemName
();
if
(
role
==
Qt
::
Edit
Role
)
return
item
->
realItemName
()
;
if
(
role
==
Qt
::
ToolTip
Role
)
return
{}
;
return
{};
}
Qt
::
ItemFlags
DatafilesQModel
::
flags
(
const
QModelIndex
&
index
)
const
{
if
(
isHeadline
(
index
)
||
!
index
.
isValid
())
return
Qt
::
NoItemFlags
;
auto
f
=
QAbstractItemModel
::
flags
(
index
);
f
|=
Qt
::
ItemIsSelectable
|
Qt
::
ItemIsEnabled
|
Qt
::
ItemIsDragEnabled
;
if
(
index
.
column
()
==
0
)
// col 0 contains name of the data entry
f
|=
Qt
::
ItemIsEditable
;
return
f
;
}
DatafileItem
*
DatafilesQModel
::
itemForIndex
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
nullptr
;
return
reinterpret_cast
<
DatafileItem
*>
(
index
.
internalPointer
());
return
m_model
->
dfileItemAt
(
index
.
row
());
}
QModelIndex
DatafilesQModel
::
indexForItem
(
const
DatafileItem
*
item
)
const
...
...
@@ -149,10 +79,3 @@ QModelIndex DatafilesQModel::indexForItem(const DatafileItem* item) const
return
createIndex
(
i
,
0
,
item
);
return
{};
}
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
+
5
−
11
View file @
6fd7a6e4
...
...
@@ -15,36 +15,30 @@
#ifndef BORNAGAIN_GUI_MODEL_FILES_DATAFILESQMODEL_H
#define BORNAGAIN_GUI_MODEL_FILES_DATAFILESQMODEL_H
#include
<QAbstract
Item
Model>
#include
<QAbstract
List
Model>
class
DatafileItem
;
class
DatafilesSet
;
//! Tree representation of DatafilesSet, for use in DatafilesSelector.
class
DatafilesQModel
:
public
QAbstract
Item
Model
{
class
DatafilesQModel
:
public
QAbstract
List
Model
{
Q_OBJECT
public:
explicit
DatafilesQModel
(
QObject
*
parent
,
DatafilesSet
*
model
);
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
override
;
void
injectDatafileItem
(
DatafileItem
*
item
);
void
removeDatafileItemAt
(
int
row
);
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
=
{})
const
override
;
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
{})
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
{})
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
override
;
DatafileItem
*
itemForIndex
(
const
QModelIndex
&
index
)
const
;
DatafileItem
*
itemForIndex
(
const
QModelIndex
&
index
)
const
;
QModelIndex
indexForItem
(
const
DatafileItem
*
item
)
const
;
const
DatafileItem
*
topMostItem
()
const
;
//!< The topmost visible item. Can be null.
bool
isHeadline
(
const
QModelIndex
&
index
)
const
;
bool
isHeadline
(
const
QModelIndex
&
)
const
{
return
false
;
}
private
:
QModelIndex
indexOfHeadline
()
const
;
DatafilesSet
*
const
m_model
;
};
...
...
This diff is collapsed.
Click to expand it.
GUI/Model/Files/DatafilesSet.h
+
1
−
0
View file @
6fd7a6e4
...
...
@@ -41,6 +41,7 @@ public:
size_t
size
()
const
{
return
m_dfile_items
.
size
();
}
const
OwningVector
<
DatafileItem
>&
dfileItems
()
const
{
return
m_dfile_items
;
}
const
DatafileItem
*
dfileItemAt
(
int
i
)
const
{
return
m_dfile_items
.
at
(
i
);
}
DatafileItem
*
dfileItemAt
(
int
i
)
{
return
m_dfile_items
.
at
(
i
);
}
QStringList
realItemNames
()
const
;
int
currentIndex
()
const
{
return
m_current_index
;
}
void
writeTo
(
QXmlStreamWriter
*
w
)
const
;
...
...
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