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
997f653f
Commit
997f653f
authored
1 year ago
by
AlQuemist
Browse files
Options
Downloads
Patches
Plain Diff
convert GUI/View/Instrument/InstrumentLibraryEditor.ui to C++ code
parent
f41bf486
No related branches found
No related tags found
1 merge request
!2148
Replace Qt UI files with C++ code
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/View/Instrument/InstrumentLibraryEditor.cpp
+74
-43
74 additions, 43 deletions
GUI/View/Instrument/InstrumentLibraryEditor.cpp
GUI/View/Instrument/InstrumentLibraryEditor.h
+8
-5
8 additions, 5 deletions
GUI/View/Instrument/InstrumentLibraryEditor.h
with
82 additions
and
48 deletions
GUI/View/Instrument/InstrumentLibraryEditor.cpp
+
74
−
43
View file @
997f653f
...
...
@@ -24,41 +24,76 @@
#include
"GUI/View/Item/ItemViewOverlayButtons.h"
#include
"GUI/View/Tool/ItemDelegateForHTML.h"
#include
"GUI/View/Widget/ApplicationSettings.h"
#include
"ui_InstrumentLibraryEditor.h"
#include
<QAction>
#include
<QFormLayout>
#include
<QInputDialog>
#include
<QPushButton>
#include
<QTextEdit>
// UI
#include
<QDialog>
#include
<QDialogButtonBox>
#include
<QScrollArea>
#include
<QSplitter>
#include
<QTreeView>
#include
<QVBoxLayout>
InstrumentLibraryEditor
::
InstrumentLibraryEditor
(
QWidget
*
parent
,
InstrumentLibrary
*
instrumentLibrary
)
:
QDialog
(
parent
)
,
m_instrumentLibrary
(
instrumentLibrary
)
,
m_ui
(
new
Ui
::
InstrumentLibraryEditor
)
,
m_treeModel
(
new
TreeModel
(
this
,
instrumentLibrary
->
instrumentModel
()))
,
m_chosenItem
(
nullptr
)
{
m_ui
->
setupUi
(
this
);
// object name is needed to reload application settings
if
(
this
->
objectName
().
isEmpty
())
this
->
setObjectName
(
"InstrumentLibraryEditor"
);
setGeometry
(
0
,
0
,
780
,
429
);
auto
*
verticalLayout
=
new
QVBoxLayout
(
this
);
setLayout
(
verticalLayout
);
auto
*
splitter
=
new
QSplitter
;
verticalLayout
->
addWidget
(
splitter
);
splitter
->
setOrientation
(
Qt
::
Horizontal
);
m_treeView
=
new
QTreeView
;
splitter
->
addWidget
(
m_treeView
);
m_scrollArea
=
new
QScrollArea
;
splitter
->
addWidget
(
m_scrollArea
);
m_scrollArea
->
setWidgetResizable
(
true
);
auto
*
scrollAreaWidgetContents
=
new
QWidget
;
scrollAreaWidgetContents
->
setGeometry
(
0
,
0
,
69
,
380
);
m_scrollArea
->
setWidget
(
scrollAreaWidgetContents
);
m_buttonBox
=
new
QDialogButtonBox
;
verticalLayout
->
addWidget
(
m_buttonBox
);
m_buttonBox
->
setOrientation
(
Qt
::
Horizontal
);
m_buttonBox
->
setStandardButtons
(
QDialogButtonBox
::
Cancel
|
QDialogButtonBox
::
Ok
);
setWindowIcon
(
QIcon
(
":/images/library.svg"
));
setWindowFlag
(
Qt
::
WindowContextHelpButtonHint
,
false
);
m_treeModel
->
enableEmptyHeadlines
(
false
);
m_
ui
->
treeView
->
setItemsExpandable
(
false
);
m_
ui
->
treeView
->
setRootIsDecorated
(
false
);
m_
ui
->
treeView
->
setHeaderHidden
(
true
);
m_
ui
->
treeView
->
setContextMenuPolicy
(
Qt
::
CustomContextMenu
);
m_
ui
->
treeView
->
setModel
(
m_treeModel
);
m_
ui
->
treeView
->
expandAll
();
m_
ui
->
treeView
->
setVerticalScrollMode
(
QTreeView
::
ScrollPerPixel
);
m_
ui
->
treeView
->
setIndentation
(
0
);
m_
ui
->
treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
m_
ui
->
treeView
->
setIconSize
(
QSize
(
128
,
128
));
m_treeView
->
setItemsExpandable
(
false
);
m_treeView
->
setRootIsDecorated
(
false
);
m_treeView
->
setHeaderHidden
(
true
);
m_treeView
->
setContextMenuPolicy
(
Qt
::
CustomContextMenu
);
m_treeView
->
setModel
(
m_treeModel
);
m_treeView
->
expandAll
();
m_treeView
->
setVerticalScrollMode
(
QTreeView
::
ScrollPerPixel
);
m_treeView
->
setIndentation
(
0
);
m_treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
m_treeView
->
setIconSize
(
QSize
(
128
,
128
));
connect
(
m_treeModel
,
&
QAbstractItemModel
::
modelReset
,
[
this
]()
{
m_ui
->
treeView
->
expandAll
();
});
connect
(
m_treeModel
,
&
QAbstractItemModel
::
modelReset
,
[
this
]()
{
m_treeView
->
expandAll
();
});
connect
(
m_buttonBox
,
&
QDialogButtonBox
::
accepted
,
this
,
&
InstrumentLibraryEditor
::
accept
);
connect
(
m_buttonBox
,
&
QDialogButtonBox
::
rejected
,
this
,
&
InstrumentLibraryEditor
::
reject
);
// ensure a current item when widget is shown
GUI
::
Style
::
setResizable
(
this
);
...
...
@@ -75,12 +110,12 @@ InstrumentItem* InstrumentLibraryEditor::execChoose()
setWindowTitle
(
"Instrument Library - Choose instrument"
);
ItemViewOverlayButtons
::
install
(
m_
ui
->
treeView
,
[
this
](
const
QModelIndex
&
i
,
bool
h
)
{
return
getOverlayActions
(
i
,
h
);
});
m_
ui
->
treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
m_treeView
,
[
this
](
const
QModelIndex
&
i
,
bool
h
)
{
return
getOverlayActions
(
i
,
h
);
});
m_treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
connect
(
m_
ui
->
treeView
,
&
QTreeView
::
doubleClicked
,
this
,
connect
(
m_treeView
,
&
QTreeView
::
doubleClicked
,
this
,
&
InstrumentLibraryEditor
::
onItemDoubleClickedForChoose
);
connect
(
m_
ui
->
treeView
->
selectionModel
(),
&
QItemSelectionModel
::
currentChanged
,
this
,
connect
(
m_treeView
->
selectionModel
(),
&
QItemSelectionModel
::
currentChanged
,
this
,
&
InstrumentLibraryEditor
::
onCurrentChangedForChoose
);
onCurrentChangedForChoose
();
...
...
@@ -100,19 +135,15 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd)
m_treeModel
->
setNewInstrument
(
addedInstrument
);
ItemViewOverlayButtons
::
install
(
m_
ui
->
treeView
,
[
this
](
const
QModelIndex
&
i
,
bool
h
)
{
return
getOverlayActions
(
i
,
h
);
});
m_
ui
->
treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
connect
(
m_
ui
->
treeView
->
selectionModel
(),
&
QItemSelectionModel
::
currentChanged
,
this
,
m_treeView
,
[
this
](
const
QModelIndex
&
i
,
bool
h
)
{
return
getOverlayActions
(
i
,
h
);
});
m_treeView
->
setItemDelegate
(
new
ItemDelegateForHTML
(
this
));
connect
(
m_treeView
->
selectionModel
(),
&
QItemSelectionModel
::
currentChanged
,
this
,
&
InstrumentLibraryEditor
::
createWidgetsForCurrentInstrument
);
m_ui
->
buttonBox
->
addButton
(
QDialogButtonBox
::
Close
);
m_ui
->
buttonBox
->
button
(
QDialogButtonBox
::
Ok
)
->
hide
();
m_ui
->
buttonBox
->
button
(
QDialogButtonBox
::
Cancel
)
->
hide
();
QModelIndex
index
=
m_treeModel
->
indexForItem
(
addedInstrument
);
m_
ui
->
treeView
->
expandAll
();
m_
ui
->
treeView
->
setCurrentIndex
(
index
);
m_
ui
->
treeView
->
scrollTo
(
index
,
QAbstractItemView
::
PositionAtTop
);
m_treeView
->
expandAll
();
m_treeView
->
setCurrentIndex
(
index
);
m_treeView
->
scrollTo
(
index
,
QAbstractItemView
::
PositionAtTop
);
createWidgetsForCurrentInstrument
();
exec
();
}
...
...
@@ -126,8 +157,8 @@ void InstrumentLibraryEditor::onItemDoubleClickedForChoose(const QModelIndex& in
void
InstrumentLibraryEditor
::
onCurrentChangedForChoose
()
{
m_chosenItem
=
m_treeModel
->
itemForIndex
(
m_
ui
->
treeView
->
currentIndex
());
m_
ui
->
buttonBox
->
button
(
QDialogButtonBox
::
Ok
)
->
setEnabled
(
m_chosenItem
!=
nullptr
);
m_chosenItem
=
m_treeModel
->
itemForIndex
(
m_treeView
->
currentIndex
());
m_buttonBox
->
button
(
QDialogButtonBox
::
Ok
)
->
setEnabled
(
m_chosenItem
!=
nullptr
);
createWidgetsForCurrentInstrument
();
}
...
...
@@ -156,17 +187,17 @@ QList<QAction*> InstrumentLibraryEditor::getOverlayActions(const QModelIndex& in
void
InstrumentLibraryEditor
::
createWidgetsForCurrentInstrument
()
{
auto
*
currentInstrument
=
m_treeModel
->
itemForIndex
(
m_
ui
->
treeView
->
currentIndex
());
auto
*
currentInstrument
=
m_treeModel
->
itemForIndex
(
m_treeView
->
currentIndex
());
if
(
!
currentInstrument
)
{
m_
ui
->
scrollArea
->
setWidget
(
new
QWidget
(
m_
ui
->
scrollArea
));
// blank widget
m_scrollArea
->
setWidget
(
new
QWidget
(
m_scrollArea
));
// blank widget
return
;
}
QWidget
*
w
=
new
QWidget
(
m_
ui
->
scrollArea
);
QWidget
*
w
=
new
QWidget
(
m_scrollArea
);
auto
*
layout
=
new
QVBoxLayout
(
w
);
auto
title
=
QString
(
"Summary (%1 instrument)"
).
arg
(
currentInstrument
->
instrumentType
());
auto
*
g
=
new
CollapsibleGroupBox
(
title
,
m_
ui
->
scrollArea
,
currentInstrument
->
expandInfo
);
auto
*
g
=
new
CollapsibleGroupBox
(
title
,
m_scrollArea
,
currentInstrument
->
expandInfo
);
g
->
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
);
auto
*
formLayout
=
new
QFormLayout
(
g
->
body
());
formLayout
->
setContentsMargins
(
17
,
17
,
17
,
17
);
...
...
@@ -191,40 +222,40 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument()
auto
*
ec
=
m_instrumentLibrary
->
editController
();
if
(
auto
*
sp
=
dynamic_cast
<
SpecularInstrumentItem
*>
(
currentInstrument
))
{
auto
*
editor
=
new
SpecularInstrumentEditor
(
m_
ui
->
scrollArea
,
sp
,
ec
);
auto
*
editor
=
new
SpecularInstrumentEditor
(
m_scrollArea
,
sp
,
ec
);
connect
(
editor
,
&
SpecularInstrumentEditor
::
dataChanged
,
this
,
&
InstrumentLibraryEditor
::
onInstrumentChangedByEditor
);
layout
->
addWidget
(
editor
);
}
else
if
(
auto
*
os
=
dynamic_cast
<
OffspecInstrumentItem
*>
(
currentInstrument
))
{
auto
*
editor
=
new
OffspecInstrumentEditor
(
m_
ui
->
scrollArea
,
os
,
ec
);
auto
*
editor
=
new
OffspecInstrumentEditor
(
m_scrollArea
,
os
,
ec
);
connect
(
editor
,
&
OffspecInstrumentEditor
::
dataChanged
,
this
,
&
InstrumentLibraryEditor
::
onInstrumentChangedByEditor
);
layout
->
addWidget
(
editor
);
}
else
if
(
auto
*
gisas
=
dynamic_cast
<
GISASInstrumentItem
*>
(
currentInstrument
))
{
auto
*
editor
=
new
GISASInstrumentEditor
(
m_
ui
->
scrollArea
,
gisas
);
auto
*
editor
=
new
GISASInstrumentEditor
(
m_scrollArea
,
gisas
);
connect
(
editor
,
&
GISASInstrumentEditor
::
dataChanged
,
this
,
&
InstrumentLibraryEditor
::
onInstrumentChangedByEditor
);
layout
->
addWidget
(
editor
);
}
else
if
(
auto
*
dp
=
dynamic_cast
<
DepthprobeInstrumentItem
*>
(
currentInstrument
))
{
auto
*
editor
=
new
DepthprobeInstrumentEditor
(
m_
ui
->
scrollArea
,
dp
,
ec
);
auto
*
editor
=
new
DepthprobeInstrumentEditor
(
m_scrollArea
,
dp
,
ec
);
connect
(
editor
,
&
DepthprobeInstrumentEditor
::
dataChanged
,
this
,
&
InstrumentLibraryEditor
::
onInstrumentChangedByEditor
);
layout
->
addWidget
(
editor
);
}
else
ASSERT_NEVER
;
m_
ui
->
scrollArea
->
setWidget
(
w
);
m_scrollArea
->
setWidget
(
w
);
}
void
InstrumentLibraryEditor
::
onInstrumentNameEdited
(
const
QString
&
newName
)
{
QModelIndex
index
=
m_
ui
->
treeView
->
currentIndex
();
QModelIndex
index
=
m_treeView
->
currentIndex
();
m_treeModel
->
setData
(
index
,
newName
,
Qt
::
EditRole
);
}
void
InstrumentLibraryEditor
::
onInstrumentDescriptionEdited
(
const
QString
&
t
)
{
QModelIndex
index
=
m_
ui
->
treeView
->
currentIndex
();
QModelIndex
index
=
m_treeView
->
currentIndex
();
m_treeModel
->
setData
(
index
,
t
,
Qt
::
ToolTipRole
);
}
...
...
@@ -232,7 +263,7 @@ void InstrumentLibraryEditor::onInstrumentChangedByEditor()
{
// uses 'MultiInstrumentNotifier::instrumentChanged' signal to set
// 'InstrumentLibrary:m_modified' flag to true ==> save library on close.
auto
*
currentInstrument
=
m_treeModel
->
itemForIndex
(
m_
ui
->
treeView
->
currentIndex
());
auto
*
currentInstrument
=
m_treeModel
->
itemForIndex
(
m_treeView
->
currentIndex
());
m_instrumentLibrary
->
editController
()
->
notifyInstrumentChanged
(
currentInstrument
);
}
...
...
This diff is collapsed.
Click to expand it.
GUI/View/Instrument/InstrumentLibraryEditor.h
+
8
−
5
View file @
997f653f
...
...
@@ -21,10 +21,9 @@
class
InstrumentItem
;
class
InstrumentLibrary
;
namespace
Ui
{
class
InstrumentLibraryEditor
;
}
class
QTreeView
;
class
QScrollArea
;
class
QDialogButtonBox
;
class
InstrumentLibraryEditor
:
public
QDialog
{
Q_OBJECT
...
...
@@ -66,9 +65,13 @@ private:
};
InstrumentLibrary
*
m_instrumentLibrary
;
Ui
::
InstrumentLibraryEditor
*
m_ui
;
TreeModel
*
m_treeModel
;
InstrumentItem
*
m_chosenItem
;
// UI
QTreeView
*
m_treeView
;
QScrollArea
*
m_scrollArea
;
QDialogButtonBox
*
m_buttonBox
;
};
#endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTLIBRARYEDITOR_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