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
ca05bc60
Commit
ca05bc60
authored
8 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
PythonScriptWidget cleanup from old WarningSign.
parent
35438b46
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.cpp
+11
-60
11 additions, 60 deletions
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.cpp
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.h
+10
-17
10 additions, 17 deletions
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.h
with
21 additions
and
77 deletions
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.cpp
+
11
−
60
View file @
ca05bc60
...
...
@@ -18,33 +18,25 @@
#include
"DesignerHelper.h"
#include
"DomainSimulationBuilder.h"
#include
"GISASSimulation.h"
#include
"InstrumentModel.h"
#include
"PythonFormatting.h"
#include
"PythonSyntaxHighlighter.h"
#include
"SampleModel.h"
#include
"SimulationOptionsItem.h"
#include
"WarningSignWidget.h"
#include
"projectdocument.h"
#include
"projectmanager.h"
#include
<QDir>
#include
<QFile>
#include
"WarningSign.h"
#include
<QFileDialog>
#include
<QMessageBox>
#include
<QPushButton>
#include
<QScrollBar>
#include
<QStandardPaths>
#include
<QStyle>
#include
<QTextEdit>
#include
<QTextStream>
#include
<QToolBar>
#include
<QToolButton>
#include
<QVBoxLayout>
#include
<memory>
PythonScriptWidget
::
PythonScriptWidget
(
QWidget
*
parent
)
:
QDialog
(
parent
)
,
m_toolBar
(
0
)
,
m_textEdit
(
0
)
,
m_warningSign
(
0
)
,
m_textEdit
(
new
QTextEdit
)
,
m_warningSign
(
new
WarningSign
(
m_textEdit
)
)
{
setWindowTitle
(
"Python Script View"
);
setMinimumSize
(
128
,
128
);
...
...
@@ -65,7 +57,6 @@ PythonScriptWidget::PythonScriptWidget(QWidget *parent)
exportToFileButton
->
setAutoDefault
(
false
);
m_toolBar
->
addWidget
(
exportToFileButton
);
m_textEdit
=
new
QTextEdit
;
m_textEdit
->
setReadOnly
(
true
);
QFont
textFont
(
"Monospace"
);
m_textEdit
->
setFont
(
textFont
);
...
...
@@ -91,11 +82,9 @@ void PythonScriptWidget::generatePythonScript(const MultiLayerItem *sampleItem,
const
QString
&
outputDir
)
{
m_outputDir
=
outputDir
;
m_warningSign
->
clear
();
delete
m_warningSign
;
m_warningSign
=
0
;
try
{
try
{
const
std
::
unique_ptr
<
GISASSimulation
>
P_simulation
(
DomainSimulationBuilder
::
getSimulation
(
sampleItem
,
instrumentItem
,
optionItem
));
...
...
@@ -105,41 +94,26 @@ void PythonScriptWidget::generatePythonScript(const MultiLayerItem *sampleItem,
m_textEdit
->
setText
(
code
);
}
catch
(
const
std
::
exception
&
ex
)
{
m_warningSign
=
new
WarningSignWidget
(
this
);
QString
message
=
QString
(
"Generation of Python Script failed. Code is not complete.
\n\n
"
"It can happen if sample requires further assembling or some of sample parameters "
"are not valid. See details below.
\n\n
%1"
).
arg
(
QString
::
fromStdString
(
ex
.
what
()));
m_warningSign
->
setWarningMessage
(
message
);
QPoint
pos
=
getPositionForWarningSign
();
m_warningSign
->
setPosition
(
pos
.
x
(),
pos
.
y
());
m_warningSign
->
show
();
}
}
//! adjusts position of warning label on widget move
void
PythonScriptWidget
::
resizeEvent
(
QResizeEvent
*
event
)
{
Q_UNUSED
(
event
);
if
(
m_warningSign
)
{
QPoint
pos
=
getPositionForWarningSign
();
m_warningSign
->
setPosition
(
pos
.
x
(),
pos
.
y
());
}
}
void
PythonScriptWidget
::
onExportToFileButton
()
{
QString
dirname
(
m_outputDir
);
if
(
dirname
.
isEmpty
())
if
(
dirname
.
isEmpty
())
dirname
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
HomeLocation
);
QString
file_name
=
QFileDialog
::
getSaveFileName
(
this
,
"Select file"
,
dirname
,
"Python scipts (*.py)"
,
0
,
QFileDialog
::
DontResolveSymlinks
);
QString
file_name
=
QFileDialog
::
getSaveFileName
(
this
,
"Select file"
,
dirname
,
"Python scipts (*.py)"
,
0
,
QFileDialog
::
DontResolveSymlinks
);
if
(
file_name
.
isEmpty
())
return
;
if
(
file_name
.
isEmpty
())
return
;
QFile
file
(
file_name
);
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
))
{
...
...
@@ -154,26 +128,3 @@ void PythonScriptWidget::onExportToFileButton()
file
.
close
();
raise
();
}
//! Returns position for warning sign at the bottom left corner of the editor. The position will
//! be adjusted according to the visibility of scroll bars
QPoint
PythonScriptWidget
::
getPositionForWarningSign
()
{
const
int
warning_sign_xpos
=
38
;
const
int
warning_sign_ypos
=
38
;
int
x
=
width
()
-
warning_sign_xpos
;
int
y
=
height
()
-
warning_sign_ypos
;
if
(
QScrollBar
*
horizontal
=
m_textEdit
->
horizontalScrollBar
())
{
if
(
horizontal
->
isVisible
())
y
-=
horizontal
->
height
();
}
if
(
QScrollBar
*
vertical
=
m_textEdit
->
verticalScrollBar
())
{
if
(
vertical
->
isVisible
())
x
-=
vertical
->
width
();
}
return
QPoint
(
x
,
y
);
}
This diff is collapsed.
Click to expand it.
GUI/coregui/Views/SimulationWidgets/PythonScriptWidget.h
+
10
−
17
View file @
ca05bc60
...
...
@@ -22,40 +22,33 @@
class
QToolBar
;
class
QTextEdit
;
class
WarningSignWidget
;
class
ProjectManager
;
class
SampleModel
;
class
InstrumentModel
;
class
WarningSign
;
class
MultiLayerItem
;
class
InstrumentItem
;
class
SimulationOptionsItem
;
//! The PythonScriptWidget displays a python script which represents full simulation.
//! Part of SimulationSetupWidget
class
BA_CORE_API_
PythonScriptWidget
:
public
QDialog
{
Q_OBJECT
public:
PythonScriptWidget
(
QWidget
*
parent
=
0
);
void
generatePythonScript
(
const
MultiLayerItem
*
sampleItem
,
const
InstrumentItem
*
instrumentItem
,
const
SimulationOptionsItem
*
optionItem
=
0
,
const
QString
&
outputDir
=
QString
());
PythonScriptWidget
(
QWidget
*
parent
=
0
);
protected:
virtual
void
resizeEvent
(
QResizeEvent
*
event
);
void
generatePythonScript
(
const
MultiLayerItem
*
sampleItem
,
const
InstrumentItem
*
instrumentItem
,
const
SimulationOptionsItem
*
optionItem
=
0
,
const
QString
&
outputDir
=
QString
());
private
slots
:
void
onExportToFileButton
();
private:
QPoint
getPositionForWarningSign
();
QToolBar
*
m_toolBar
;
QTextEdit
*
m_textEdit
;
WarningSignWidget
*
m_warningSign
;
QToolBar
*
m_toolBar
;
QTextEdit
*
m_textEdit
;
WarningSign
*
m_warningSign
;
QString
m_outputDir
;
};
...
...
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