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
628c4c36
Commit
628c4c36
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
rm obsolete ItemSelectorWidget
parent
55e5a889
No related branches found
No related tags found
1 merge request
!476
Reduce SessionModelView ("Model tech view")
Pipeline
#50239
failed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/View/Common/ItemSelectorWidget.cpp
+0
-140
0 additions, 140 deletions
GUI/View/Common/ItemSelectorWidget.cpp
GUI/View/Common/ItemSelectorWidget.h
+0
-72
0 additions, 72 deletions
GUI/View/Common/ItemSelectorWidget.h
with
0 additions
and
212 deletions
GUI/View/Common/ItemSelectorWidget.cpp
deleted
100644 → 0
+
0
−
140
View file @
55e5a889
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Common/ItemSelectorWidget.cpp
//! @brief Implements class ItemSelectorWidget
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include
"GUI/View/Common/ItemSelectorWidget.h"
#include
"GUI/Model/Session/SessionDecorationModel.h"
#include
"GUI/Model/Session/SessionModel.h"
#include
"GUI/View/Tool/mainwindow_constants.h"
#include
<QListView>
#include
<QVBoxLayout>
ItemSelectorWidget
::
ItemSelectorWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
),
m_listView
(
new
QListView
),
m_model
(
nullptr
)
{
setSizePolicy
(
QSizePolicy
::
Preferred
,
QSizePolicy
::
Expanding
);
auto
*
layout
=
new
QVBoxLayout
;
layout
->
setMargin
(
0
);
layout
->
addWidget
(
m_listView
);
setLayout
(
layout
);
m_listView
->
setContextMenuPolicy
(
Qt
::
CustomContextMenu
);
m_listView
->
setAttribute
(
Qt
::
WA_MacShowFocusRect
,
false
);
connect
(
m_listView
,
&
QListView
::
customContextMenuRequested
,
this
,
&
ItemSelectorWidget
::
onCustomContextMenuRequested
);
}
ItemSelectorWidget
::~
ItemSelectorWidget
()
=
default
;
QSize
ItemSelectorWidget
::
sizeHint
()
const
{
return
QSize
(
GUI
::
Constants
::
ITEM_SELECTOR_WIDGET_WIDTH
,
GUI
::
Constants
::
ITEM_SELECTOR_WIDGET_HEIGHT
);
}
QSize
ItemSelectorWidget
::
minimumSizeHint
()
const
{
return
QSize
(
25
,
25
);
}
void
ItemSelectorWidget
::
setModel
(
SessionModel
*
model
)
{
if
(
model
==
m_model
)
return
;
disconnectModel
();
m_model
=
model
;
connectModel
();
}
void
ItemSelectorWidget
::
setItemDelegate
(
QAbstractItemDelegate
*
delegate
)
{
m_listView
->
setItemDelegate
(
delegate
);
}
QItemSelectionModel
*
ItemSelectorWidget
::
selectionModel
()
{
return
m_listView
->
selectionModel
();
}
QListView
*
ItemSelectorWidget
::
listView
()
{
return
m_listView
;
}
void
ItemSelectorWidget
::
select
(
const
QModelIndex
&
index
,
QItemSelectionModel
::
SelectionFlags
command
)
{
selectionModel
()
->
select
(
index
,
command
);
}
//! select last item if no selection exists
void
ItemSelectorWidget
::
updateSelection
()
{
if
(
!
selectionModel
()
->
hasSelection
())
selectLast
();
}
void
ItemSelectorWidget
::
selectLast
()
{
QModelIndex
itemIndex
=
m_model
->
index
(
m_model
->
rowCount
(
QModelIndex
())
-
1
,
0
,
QModelIndex
());
selectionModel
()
->
select
(
itemIndex
,
QItemSelectionModel
::
ClearAndSelect
);
}
void
ItemSelectorWidget
::
onSelectionChanged
(
const
QItemSelection
&
selected
,
const
QItemSelection
&
)
{
QModelIndexList
indexes
=
selected
.
indexes
();
SessionItem
*
selectedItem
(
nullptr
);
if
(
!
indexes
.
empty
())
selectedItem
=
m_model
->
itemForIndex
(
indexes
.
back
());
emit
selectionChanged
(
selectedItem
);
}
void
ItemSelectorWidget
::
onCustomContextMenuRequested
(
const
QPoint
&
point
)
{
emit
contextMenuRequest
(
m_listView
->
mapToGlobal
(
point
),
m_listView
->
indexAt
(
point
));
}
void
ItemSelectorWidget
::
connectModel
()
{
if
(
!
m_model
)
return
;
m_decorationModel
=
std
::
make_unique
<
SessionDecorationModel
>
(
nullptr
,
m_model
);
m_listView
->
setModel
(
m_decorationModel
.
get
());
connect
(
m_listView
->
selectionModel
(),
&
QItemSelectionModel
::
selectionChanged
,
this
,
&
ItemSelectorWidget
::
onSelectionChanged
,
Qt
::
UniqueConnection
);
}
void
ItemSelectorWidget
::
disconnectModel
()
{
m_listView
->
setModel
(
nullptr
);
m_model
=
nullptr
;
}
//! provide default selection when widget is shown
void
ItemSelectorWidget
::
showEvent
(
QShowEvent
*
)
{
if
(
!
m_model
||
!
selectionModel
())
return
;
if
(
selectionModel
()
->
selectedIndexes
().
isEmpty
()
&&
m_model
->
rowCount
(
QModelIndex
())
!=
0
)
selectionModel
()
->
select
(
m_model
->
index
(
0
,
0
,
QModelIndex
()),
QItemSelectionModel
::
Select
);
}
This diff is collapsed.
Click to expand it.
GUI/View/Common/ItemSelectorWidget.h
deleted
100644 → 0
+
0
−
72
View file @
55e5a889
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Common/ItemSelectorWidget.h
//! @brief Defines class ItemSelectorWidget
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_VIEW_COMMON_ITEMSELECTORWIDGET_H
#define BORNAGAIN_GUI_VIEW_COMMON_ITEMSELECTORWIDGET_H
#include
<QItemSelectionModel>
#include
<QWidget>
#include
<memory>
class
SessionModel
;
class
SessionItem
;
class
QItemSelection
;
class
QModelIndex
;
class
QAbstractItemDelegate
;
class
QListView
;
class
SessionDecorationModel
;
//! The ItemSelectorWidget class holds QListView to show top level items of SessionModel.
//! Used in InstrumentView and JobSelectorView to switch between items.
class
ItemSelectorWidget
:
public
QWidget
{
Q_OBJECT
public:
ItemSelectorWidget
(
QWidget
*
parent
=
nullptr
);
~
ItemSelectorWidget
()
override
;
QSize
sizeHint
()
const
override
;
QSize
minimumSizeHint
()
const
override
;
void
setModel
(
SessionModel
*
model
);
void
setItemDelegate
(
QAbstractItemDelegate
*
delegate
);
QItemSelectionModel
*
selectionModel
();
QListView
*
listView
();
public
slots
:
void
select
(
const
QModelIndex
&
index
,
QItemSelectionModel
::
SelectionFlags
command
);
void
updateSelection
();
void
selectLast
();
signals:
void
selectionChanged
(
SessionItem
*
item
);
void
contextMenuRequest
(
const
QPoint
&
point
,
const
QModelIndex
&
index
);
private
slots
:
void
onSelectionChanged
(
const
QItemSelection
&
selected
,
const
QItemSelection
&
);
void
onCustomContextMenuRequested
(
const
QPoint
&
point
);
protected:
void
connectModel
();
void
disconnectModel
();
void
showEvent
(
class
QShowEvent
*
)
override
;
QListView
*
m_listView
;
SessionModel
*
m_model
;
std
::
unique_ptr
<
SessionDecorationModel
>
m_decorationModel
;
};
#endif // BORNAGAIN_GUI_VIEW_COMMON_ITEMSELECTORWIDGET_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