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
82fc453a
Commit
82fc453a
authored
8 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
ModelMapper now informs about a child being deleted.
parent
3a9cb133
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GUI/coregui/Models/ModelMapper.cpp
+18
-1
18 additions, 1 deletion
GUI/coregui/Models/ModelMapper.cpp
GUI/coregui/Models/ModelMapper.h
+4
-0
4 additions, 0 deletions
GUI/coregui/Models/ModelMapper.h
Tests/UnitTests/GUI/TestMapperForItem.h
+36
-0
36 additions, 0 deletions
Tests/UnitTests/GUI/TestMapperForItem.h
with
58 additions
and
1 deletion
GUI/coregui/Models/ModelMapper.cpp
+
18
−
1
View file @
82fc453a
...
@@ -72,6 +72,11 @@ void ModelMapper::setOnItemDestroy(std::function<void (SessionItem *)> f, const
...
@@ -72,6 +72,11 @@ void ModelMapper::setOnItemDestroy(std::function<void (SessionItem *)> f, const
m_onItemDestroy
.
push_back
(
call_item_t
(
f
,
caller
));
m_onItemDestroy
.
push_back
(
call_item_t
(
f
,
caller
));
}
}
void
ModelMapper
::
setOnAboutToRemoveChild
(
std
::
function
<
void
(
SessionItem
*
)
>
f
,
const
void
*
caller
)
{
m_onAboutToRemoveChild
.
push_back
(
call_item_t
(
f
,
caller
));
}
//! Cancells all subscribtion of given caller
//! Cancells all subscribtion of given caller
void
ModelMapper
::
unsubscribe
(
const
void
*
caller
)
void
ModelMapper
::
unsubscribe
(
const
void
*
caller
)
{
{
...
@@ -83,6 +88,7 @@ void ModelMapper::unsubscribe(const void *caller)
...
@@ -83,6 +88,7 @@ void ModelMapper::unsubscribe(const void *caller)
clean_container
(
m_onSiblingsChange
,
caller
);
clean_container
(
m_onSiblingsChange
,
caller
);
clean_container
(
m_onAnyChildChange
,
caller
);
clean_container
(
m_onAnyChildChange
,
caller
);
clean_container
(
m_onItemDestroy
,
caller
);
clean_container
(
m_onItemDestroy
,
caller
);
clean_container
(
m_onAboutToRemoveChild
,
caller
);
}
}
void
ModelMapper
::
setModel
(
SessionModel
*
model
)
void
ModelMapper
::
setModel
(
SessionModel
*
model
)
...
@@ -189,7 +195,16 @@ void ModelMapper::callOnAnyChildChange(SessionItem *item)
...
@@ -189,7 +195,16 @@ void ModelMapper::callOnAnyChildChange(SessionItem *item)
f
.
first
(
item
);
f
.
first
(
item
);
}
}
}
}
// if(m_active) emit anyChildChange(item);
// if(m_active) emit anyChildChange(item);
}
void
ModelMapper
::
callOnAboutToRemoveChild
(
SessionItem
*
item
)
{
if
(
m_active
&&
m_onAboutToRemoveChild
.
size
()
>
0
)
{
for
(
auto
f
:
m_onAboutToRemoveChild
)
{
f
.
first
(
item
);
}
}
}
}
//! Notifies subscribers if an item owning given mapper is about to be destroyed
//! Notifies subscribers if an item owning given mapper is about to be destroyed
...
@@ -215,6 +230,7 @@ void ModelMapper::clearMapper()
...
@@ -215,6 +230,7 @@ void ModelMapper::clearMapper()
m_onSiblingsChange
.
clear
();
m_onSiblingsChange
.
clear
();
m_onAnyChildChange
.
clear
();
m_onAnyChildChange
.
clear
();
m_onItemDestroy
.
clear
();
m_onItemDestroy
.
clear
();
m_onAboutToRemoveChild
.
clear
();
}
}
void
ModelMapper
::
onDataChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
bottomRight
,
void
ModelMapper
::
onDataChanged
(
const
QModelIndex
&
topLeft
,
const
QModelIndex
&
bottomRight
,
...
@@ -309,6 +325,7 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex &parent, int first, int /*
...
@@ -309,6 +325,7 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex &parent, int first, int /*
if
(
nestling
==
0
)
{
if
(
nestling
==
0
)
{
callOnChildrenChange
(
0
);
callOnChildrenChange
(
0
);
callOnAboutToRemoveChild
(
oldChild
);
// inform siblings about the change
// inform siblings about the change
// if(SessionItem *parent = oldChild->parent()) {
// if(SessionItem *parent = oldChild->parent()) {
...
...
This diff is collapsed.
Click to expand it.
GUI/coregui/Models/ModelMapper.h
+
4
−
0
View file @
82fc453a
...
@@ -51,6 +51,8 @@ public:
...
@@ -51,6 +51,8 @@ public:
void
setOnItemDestroy
(
std
::
function
<
void
(
SessionItem
*
)
>
f
,
const
void
*
caller
=
0
);
void
setOnItemDestroy
(
std
::
function
<
void
(
SessionItem
*
)
>
f
,
const
void
*
caller
=
0
);
void
setOnAboutToRemoveChild
(
std
::
function
<
void
(
SessionItem
*
)
>
f
,
const
void
*
caller
=
0
);
void
unsubscribe
(
const
void
*
caller
);
void
unsubscribe
(
const
void
*
caller
);
void
callOnItemDestroy
();
void
callOnItemDestroy
();
...
@@ -89,6 +91,7 @@ private:
...
@@ -89,6 +91,7 @@ private:
void
callOnChildrenChange
(
SessionItem
*
item
);
void
callOnChildrenChange
(
SessionItem
*
item
);
void
callOnSiblingsChange
();
void
callOnSiblingsChange
();
void
callOnAnyChildChange
(
SessionItem
*
item
);
void
callOnAnyChildChange
(
SessionItem
*
item
);
void
callOnAboutToRemoveChild
(
SessionItem
*
item
);
void
clearMapper
();
void
clearMapper
();
...
@@ -109,6 +112,7 @@ private:
...
@@ -109,6 +112,7 @@ private:
std
::
vector
<
call_t
>
m_onSiblingsChange
;
std
::
vector
<
call_t
>
m_onSiblingsChange
;
std
::
vector
<
call_item_t
>
m_onAnyChildChange
;
std
::
vector
<
call_item_t
>
m_onAnyChildChange
;
std
::
vector
<
call_item_t
>
m_onItemDestroy
;
std
::
vector
<
call_item_t
>
m_onItemDestroy
;
std
::
vector
<
call_item_t
>
m_onAboutToRemoveChild
;
QModelIndex
m_aboutToDelete
;
QModelIndex
m_aboutToDelete
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Tests/UnitTests/GUI/TestMapperForItem.h
+
36
−
0
View file @
82fc453a
...
@@ -16,6 +16,7 @@ public:
...
@@ -16,6 +16,7 @@ public:
,
m_onParentChangeCount
(
0
)
,
m_onParentChangeCount
(
0
)
,
m_onChildrenChangeCount
(
0
)
,
m_onChildrenChangeCount
(
0
)
,
m_onSiblingsChangeCount
(
0
)
,
m_onSiblingsChangeCount
(
0
)
,
m_onAboutToRemoveChild
(
0
)
{
}
{
}
void
clear
()
void
clear
()
...
@@ -25,6 +26,7 @@ public:
...
@@ -25,6 +26,7 @@ public:
m_onParentChangeCount
=
0
;
m_onParentChangeCount
=
0
;
m_onChildrenChangeCount
=
0
;
m_onChildrenChangeCount
=
0
;
m_onSiblingsChangeCount
=
0
;
m_onSiblingsChangeCount
=
0
;
m_onAboutToRemoveChild
=
0
;
m_reported_items
.
clear
();
m_reported_items
.
clear
();
m_reported_names
.
clear
();
m_reported_names
.
clear
();
}
}
...
@@ -65,6 +67,13 @@ public:
...
@@ -65,6 +67,13 @@ public:
onSiblingsChange
();
onSiblingsChange
();
},
caller
);
},
caller
);
mapper
->
setOnAboutToRemoveChild
(
[
this
](
SessionItem
*
item
)
{
onAboutToRemoveChild
(
item
);
},
caller
);
}
}
void
onPropertyChange
(
const
QString
&
name
)
void
onPropertyChange
(
const
QString
&
name
)
...
@@ -100,11 +109,18 @@ public:
...
@@ -100,11 +109,18 @@ public:
mapper
->
unsubscribe
(
this
);
mapper
->
unsubscribe
(
this
);
}
}
void
onAboutToRemoveChild
(
SessionItem
*
item
)
{
m_reported_items
.
append
(
item
);
m_onAboutToRemoveChild
++
;
}
int
m_onPropertyChangeCount
;
int
m_onPropertyChangeCount
;
int
m_onChildPropertyChangeCount
;
int
m_onChildPropertyChangeCount
;
int
m_onParentChangeCount
;
int
m_onParentChangeCount
;
int
m_onChildrenChangeCount
;
int
m_onChildrenChangeCount
;
int
m_onSiblingsChangeCount
;
int
m_onSiblingsChangeCount
;
int
m_onAboutToRemoveChild
;
QList
<
SessionItem
*>
m_reported_items
;
QList
<
SessionItem
*>
m_reported_items
;
QStringList
m_reported_names
;
QStringList
m_reported_names
;
};
};
...
@@ -141,6 +157,7 @@ private slots:
...
@@ -141,6 +157,7 @@ private slots:
void
test_onSiblingsChange
();
void
test_onSiblingsChange
();
void
test_Subscription
();
void
test_Subscription
();
void
test_TwoWidgetsSubscription
();
void
test_TwoWidgetsSubscription
();
void
test_AboutToRemoveChild
();
};
};
inline
void
TestMapperForItem
::
test_initialCondition
()
inline
void
TestMapperForItem
::
test_initialCondition
()
...
@@ -338,3 +355,22 @@ inline void TestMapperForItem::test_TwoWidgetsSubscription()
...
@@ -338,3 +355,22 @@ inline void TestMapperForItem::test_TwoWidgetsSubscription()
QCOMPARE
(
w2
.
m_onPropertyChangeCount
,
2
);
QCOMPARE
(
w2
.
m_onPropertyChangeCount
,
2
);
}
}
inline
void
TestMapperForItem
::
test_AboutToRemoveChild
()
{
Widget
w
;
SampleModel
model
;
SessionItem
*
container
=
model
.
insertNewItem
(
Constants
::
ProjectionContainerType
);
SessionItem
*
line
=
model
.
insertNewItem
(
Constants
::
HorizontalLineMaskType
,
container
->
index
());
setItem
(
container
,
&
w
);
QCOMPARE
(
w
.
m_onAboutToRemoveChild
,
0
);
QCOMPARE
(
w
.
m_reported_items
.
size
(),
0
);
line
->
parent
()
->
takeRow
(
line
->
parent
()
->
rowOfChild
(
line
));
QCOMPARE
(
w
.
m_onAboutToRemoveChild
,
1
);
QCOMPARE
(
w
.
m_reported_items
.
size
(),
1
);
QCOMPARE
(
w
.
m_reported_items
.
back
(),
line
);
}
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