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
a9e5a54d
Commit
a9e5a54d
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
add material-changed signaling to MaterialModel
parent
d4deea01
No related branches found
No related tags found
1 merge request
!420
Layer editor improvements3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GUI/Models/MaterialModel.cpp
+59
-0
59 additions, 0 deletions
GUI/Models/MaterialModel.cpp
GUI/Models/MaterialModel.h
+10
-0
10 additions, 0 deletions
GUI/Models/MaterialModel.h
GUI/Views/MaterialEditor/MaterialEditorDialog.cpp
+2
-3
2 additions, 3 deletions
GUI/Views/MaterialEditor/MaterialEditorDialog.cpp
with
71 additions
and
3 deletions
GUI/Models/MaterialModel.cpp
+
59
−
0
View file @
a9e5a54d
...
...
@@ -90,6 +90,16 @@ QVector<MaterialItem*> MaterialModel::materialItems() const
return
topItems
<
MaterialItem
>
();
}
MaterialItem
*
MaterialModel
::
findMaterialItem
(
const
QString
&
identifier
)
const
{
for
(
auto
*
m
:
materialItems
())
if
(
m
->
identifier
()
==
identifier
)
return
m
;
return
nullptr
;
}
void
MaterialModel
::
removeMaterial
(
const
QString
&
identifier
)
{
removeMaterial
(
materialFromIdentifier
(
identifier
));
...
...
@@ -102,6 +112,55 @@ void MaterialModel::removeMaterial(MaterialItem* materialItem)
removeRows
(
index
.
row
(),
1
,
index
.
parent
());
}
void
MaterialModel
::
readFrom
(
QXmlStreamReader
*
reader
,
MessageService
*
messageService
/*= 0*/
)
{
// do not send added-notifications until completely read - otherwise partially
// initialized items will be notified
disconnect
(
this
,
&
SessionModel
::
rowsInserted
,
this
,
&
MaterialModel
::
onRowsChange
);
SessionModel
::
readFrom
(
reader
,
messageService
);
connect
(
this
,
&
SessionModel
::
rowsInserted
,
this
,
&
MaterialModel
::
onRowsChange
);
for
(
auto
materialItem
:
materialItems
())
{
materialItem
->
mapper
()
->
setOnAnyChildChange
(
[
this
,
materialItem
](
SessionItem
*
)
{
materialChanged
(
materialItem
);
},
this
);
}
}
void
MaterialModel
::
initFrom
(
SessionModel
*
model
,
SessionItem
*
parent
)
{
// since initFrom does not send materialChanged signals, this has to be done manually.
QStringList
identifiersOfChangedMaterials
;
auto
*
sourceModel
=
dynamic_cast
<
MaterialModel
*>
(
model
);
for
(
auto
destItem
:
materialItems
())
{
auto
*
srcItem
=
sourceModel
->
findMaterialItem
(
destItem
->
identifier
());
if
(
srcItem
&&
(
*
srcItem
!=
*
destItem
))
identifiersOfChangedMaterials
<<
destItem
->
identifier
();
}
clear
();
SessionModel
::
initFrom
(
model
,
parent
);
for
(
auto
identifier
:
identifiersOfChangedMaterials
)
emit
materialChanged
(
findMaterialItem
(
identifier
));
}
void
MaterialModel
::
onRowsChange
(
const
QModelIndex
&
parent
,
int
,
int
)
{
// valid parent means not a material (which is top level item) but something below
if
(
parent
.
isValid
())
return
;
for
(
auto
materialItem
:
materialItems
())
{
materialItem
->
mapper
()
->
unsubscribe
(
this
);
materialItem
->
mapper
()
->
setOnAnyChildChange
(
[
this
,
materialItem
](
SessionItem
*
)
{
materialChanged
(
materialItem
);
},
this
);
}
}
bool
MaterialModel
::
operator
!=
(
const
MaterialModel
&
other
)
const
{
return
!
operator
==
(
other
);
...
...
This diff is collapsed.
Click to expand it.
GUI/Models/MaterialModel.h
+
10
−
0
View file @
a9e5a54d
...
...
@@ -38,13 +38,23 @@ public:
MaterialItem
*
cloneMaterial
(
MaterialItem
*
material
);
QVector
<
MaterialItem
*>
materialItems
()
const
;
MaterialItem
*
findMaterialItem
(
const
QString
&
identifier
)
const
;
void
removeMaterial
(
const
QString
&
identifier
);
void
removeMaterial
(
MaterialItem
*
materialItem
);
virtual
void
readFrom
(
QXmlStreamReader
*
reader
,
MessageService
*
messageService
=
0
)
override
;
virtual
void
initFrom
(
SessionModel
*
model
,
SessionItem
*
parent
)
override
;
//! Compares for complete equality (same material identifiers, same order of materials,...)
bool
operator
==
(
const
MaterialModel
&
other
)
const
;
bool
operator
!=
(
const
MaterialModel
&
other
)
const
;
signals:
void
materialChanged
(
MaterialItem
*
materialItem
);
private:
void
onRowsChange
(
const
QModelIndex
&
parent
,
int
,
int
);
};
#endif // BORNAGAIN_GUI_MODELS_MATERIALMODEL_H
This diff is collapsed.
Click to expand it.
GUI/Views/MaterialEditor/MaterialEditorDialog.cpp
+
2
−
3
View file @
a9e5a54d
...
...
@@ -150,10 +150,9 @@ MaterialEditorDialog::~MaterialEditorDialog()
//! replaces original material model with the model modified by MaterialEditor
void
MaterialEditorDialog
::
accept
()
{
if
(
*
m_document
->
materialModel
()
!=
*
m_tmpMaterialModel
)
{
m_document
->
materialModel
()
->
clear
();
if
(
*
m_document
->
materialModel
()
!=
*
m_tmpMaterialModel
)
m_document
->
materialModel
()
->
initFrom
(
m_tmpMaterialModel
.
get
(),
0
);
}
QDialog
::
accept
();
}
...
...
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