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
4efe2c3f
Commit
4efe2c3f
authored
9 years ago
by
David Li
Committed by
Pospelov, Gennady
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
TestProxyModel can filter out item between group item and property items
parent
93a70817
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/Views/TestComponentView.cpp
+6
-1
6 additions, 1 deletion
GUI/coregui/Views/TestComponentView.cpp
GUI/coregui/Views/TestView.cpp
+77
-2
77 additions, 2 deletions
GUI/coregui/Views/TestView.cpp
GUI/coregui/Views/TestView.h
+23
-2
23 additions, 2 deletions
GUI/coregui/Views/TestView.h
with
106 additions
and
5 deletions
GUI/coregui/Views/TestComponentView.cpp
+
6
−
1
View file @
4efe2c3f
...
...
@@ -20,6 +20,7 @@
#include
"MultiLayerItem.h"
#include
"SampleBuilderFactory.h"
#include
"GUIObjectBuilder.h"
#include
"TestView.h"
#include
<QItemSelectionModel>
#include
<QHBoxLayout>
#include
<QTreeView>
...
...
@@ -84,8 +85,12 @@ void TestComponentView::init_editors()
m_model
->
insertNewItem
(
Constants
::
ParticleType
);
// tree view
m_treeView
->
setModel
(
m_model
);
auto
x
=
new
TestProxyModel
(
this
);
x
->
setSourceModel
(
m_model
);
m_treeView
->
setModel
(
x
);
m_treeView
->
expandAll
();
m_treeView
->
resizeColumnToContents
(
0
);
m_treeView
->
setAlternatingRowColors
(
true
);
connect
(
m_treeView
->
selectionModel
(),
SIGNAL
(
selectionChanged
(
QItemSelection
,
QItemSelection
)),
this
,
SLOT
(
onSelectionChanged
(
QItemSelection
,
QItemSelection
)));
...
...
This diff is collapsed.
Click to expand it.
GUI/coregui/Views/TestView.cpp
+
77
−
2
View file @
4efe2c3f
...
...
@@ -32,6 +32,7 @@
#include
<InstrumentModel.h>
#include
<JobModel.h>
#include
<MaterialModel.h>
#include
<QPersistentModelIndex>
#include
"ModelMapper.h"
#include
"DetectorItems.h"
...
...
@@ -69,6 +70,10 @@ void TestView::test_sessionModel()
addModelToTabs
(
tabs
,
m_mainWindow
->
getMaterialModel
());
addModelToTabs
(
tabs
,
m_mainWindow
->
getJobModel
());
TestProxyModel
*
testModel
=
new
TestProxyModel
(
this
);
testModel
->
setSourceModel
(
m_mainWindow
->
getSampleModel
());
addModelToTabs
(
tabs
,
testModel
);
// do some testing here
m_mainWindow
->
getInstrumentModel
()
->
rootItem
()
->
getChildOfType
(
Constants
::
InstrumentType
)
->
mapper
()
->
setOnChildPropertyChange
(
...
...
@@ -83,14 +88,17 @@ void TestView::test_sessionModel()
setLayout
(
layout
);
}
void
TestView
::
addModelToTabs
(
QTabWidget
*
tabs
,
Session
Model
*
model
)
void
TestView
::
addModelToTabs
(
QTabWidget
*
tabs
,
QAbstractItem
Model
*
model
)
{
QTreeView
*
view
=
new
QTreeView
;
view
->
setModel
(
model
);
view
->
expandAll
();
view
->
resizeColumnToContents
(
0
);
view
->
resizeColumnToContents
(
1
);
tabs
->
addTab
(
view
,
model
->
getModelTag
());
if
(
SessionModel
*
sm
=
dynamic_cast
<
SessionModel
*>
(
model
))
tabs
->
addTab
(
view
,
sm
->
getModelTag
());
else
tabs
->
addTab
(
view
,
"Some Model"
);
}
void
TestView
::
test_MaskEditor
()
...
...
@@ -198,3 +206,70 @@ void TestView::test_RunFitWidget()
setLayout
(
layout
);
}
TestProxyModel
::
TestProxyModel
(
QObject
*
parent
)
:
QIdentityProxyModel
(
parent
)
{
}
void
TestProxyModel
::
setSourceModel
(
QAbstractItemModel
*
source
)
{
QIdentityProxyModel
::
setSourceModel
(
source
);
m_source
=
dynamic_cast
<
SessionModel
*>
(
source
);
connect
(
m_source
,
SIGNAL
(
dataChanged
(
QModelIndex
,
QModelIndex
,
QVector
<
int
>
)),
this
,
SIGNAL
(
layoutChanged
()));
}
QModelIndex
TestProxyModel
::
mapFromSource
(
const
QModelIndex
&
sourceIndex
)
const
{
return
createIndex
(
sourceIndex
.
row
(),
sourceIndex
.
column
(),
sourceIndex
.
internalPointer
());
}
QModelIndex
TestProxyModel
::
mapToSource
(
const
QModelIndex
&
proxyIndex
)
const
{
ParameterizedItem
*
item
=
static_cast
<
ParameterizedItem
*>
(
proxyIndex
.
internalPointer
());
if
(
!
item
)
{
return
QModelIndex
();
}
return
m_source
->
index
(
proxyIndex
.
row
(),
proxyIndex
.
column
(),
item
->
parent
()
->
index
());
}
QModelIndex
TestProxyModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
const
QModelIndex
sourceParent
=
mapToSource
(
parent
);
ParameterizedItem
*
parentt
=
m_source
->
itemForIndex
(
sourceParent
);
if
(
parentt
->
modelType
()
==
Constants
::
GroupItemType
)
{
ParameterizedItem
*
cur
=
parentt
->
parent
()
->
getGroupItem
(
parentt
->
itemName
());
const
QModelIndex
sourceIndex
=
m_source
->
index
(
row
,
column
,
cur
->
index
());
return
mapFromSource
(
sourceIndex
);
}
const
QModelIndex
sourceIndex
=
m_source
->
index
(
row
,
column
,
sourceParent
);
return
mapFromSource
(
sourceIndex
);
}
QModelIndex
TestProxyModel
::
parent
(
const
QModelIndex
&
child
)
const
{
const
QModelIndex
sourceIndex
=
mapToSource
(
child
);
ParameterizedItem
*
head
=
m_source
->
itemForIndex
(
sourceIndex
.
parent
());
if
(
head
&&
head
->
parent
()
&&
head
->
parent
()
->
modelType
()
==
Constants
::
GroupItemType
)
{
// skip immediate layer
return
mapFromSource
(
head
->
parent
()
->
index
());
}
const
QModelIndex
sourceParent
=
sourceIndex
.
parent
();
return
mapFromSource
(
sourceParent
);
}
int
TestProxyModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
QModelIndex
sourceParent
=
mapToSource
(
parent
);
ParameterizedItem
*
item
=
m_source
->
itemForIndex
(
sourceParent
);
if
(
item
&&
item
->
modelType
()
==
Constants
::
GroupItemType
)
{
ParameterizedItem
*
cur
=
item
->
parent
()
->
getGroupItem
(
item
->
itemName
());
if
(
cur
)
return
m_source
->
rowCount
(
cur
->
index
());
else
qDebug
()
<<
"proxy::rowCount: null pointer"
;
}
return
m_source
->
rowCount
(
sourceParent
);
}
This diff is collapsed.
Click to expand it.
GUI/coregui/Views/TestView.h
+
23
−
2
View file @
4efe2c3f
...
...
@@ -20,7 +20,7 @@
class
MainWindow
;
class
QTabWidget
;
class
Session
Model
;
class
QAbstractItem
Model
;
class
TestView
:
public
QWidget
{
...
...
@@ -33,8 +33,29 @@ private:
void
test_AccordionWidget
();
void
test_RunFitWidget
();
MainWindow
*
m_mainWindow
;
void
addModelToTabs
(
QTabWidget
*
tabs
,
Session
Model
*
model
);
void
addModelToTabs
(
QTabWidget
*
tabs
,
QAbstractItem
Model
*
model
);
void
test_sessionModel
();
};
#include
"SessionModel.h"
#include
<QObject>
#include
<QIdentityProxyModel>
#include
<QModelIndex>
class
TestProxyModel
:
public
QIdentityProxyModel
{
Q_OBJECT
public:
TestProxyModel
(
QObject
*
parent
=
0
);
void
setSourceModel
(
QAbstractItemModel
*
source
);
QModelIndex
mapFromSource
(
const
QModelIndex
&
sourceIndex
)
const
;
QModelIndex
mapToSource
(
const
QModelIndex
&
proxyIndex
)
const
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
;
QModelIndex
parent
(
const
QModelIndex
&
child
)
const
;
int
rowCount
(
const
QModelIndex
&
parent
)
const
;
private:
SessionModel
*
m_source
;
};
#endif
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