Skip to content
Snippets Groups Projects
Commit 6de0c5f6 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

free ScriptPanel from SessionItem/SessionModel knowledge

parent f7c00154
No related branches found
No related tags found
1 merge request!553Remove session signaling in sample model
......@@ -15,7 +15,6 @@
#include "GUI/View/SampleDesigner/ScriptPanel.h"
#include "Core/Export/ExportToPython.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Sample/SampleModel.h"
#include "GUI/Model/To/ToDomain.h"
#include "GUI/View/Info/CautionSign.h"
#include "GUI/View/Info/PythonSyntaxHighlighter.h"
......@@ -55,6 +54,9 @@ ScriptPanel::ScriptPanel(SampleModel* sampleModel, QWidget* parent)
QFont textFont("Monospace");
m_textEdit->setFont(textFont);
m_textEdit->setFontPointSize(DesignerHelper::getPythonEditorFontSize());
connect(m_updateTimer, &UpdateTimer::timeToUpdate, this, &ScriptPanel::updateEditor,
Qt::UniqueConnection);
}
void ScriptPanel::setCurrentSample(MultiLayerItem* multiLayerItem)
......@@ -63,6 +65,12 @@ void ScriptPanel::setCurrentSample(MultiLayerItem* multiLayerItem)
updateEditor();
}
void ScriptPanel::onSampleModified()
{
if (!isHidden())
m_updateTimer->scheduleUpdate();
}
void ScriptPanel::updateEditor()
{
if (!m_highlighter) {
......@@ -81,29 +89,14 @@ void ScriptPanel::updateEditor()
m_textEdit->verticalScrollBar()->setValue(oldScrollbarValue);
}
void ScriptPanel::setEditorConnected(bool isConnected)
{
if (isConnected) {
connect(m_sampleModel, &SampleModel::sampleChanged, m_updateTimer,
&UpdateTimer::scheduleUpdate);
connect(m_updateTimer, &UpdateTimer::timeToUpdate, this, &ScriptPanel::updateEditor,
Qt::UniqueConnection);
m_updateTimer->scheduleUpdate();
} else {
m_sampleModel->disconnect(m_updateTimer);
m_updateTimer->disconnect(this);
}
}
void ScriptPanel::showEvent(QShowEvent*)
{
setEditorConnected(isVisible());
m_updateTimer->scheduleUpdate();
}
void ScriptPanel::hideEvent(QHideEvent*)
{
setEditorConnected(isVisible());
m_updateTimer->reset();
}
QString ScriptPanel::generateCodeSnippet()
......
......@@ -36,6 +36,7 @@ public:
explicit ScriptPanel(SampleModel* sampleModel, QWidget* parent);
void setCurrentSample(MultiLayerItem* multiLayerItem);
void onSampleModified();
protected:
void showEvent(QShowEvent*) override;
......@@ -48,8 +49,6 @@ private:
//! Update the editor with the script content
void updateEditor();
void setEditorConnected(bool isConnected);
QTextEdit* m_textEdit;
SampleModel* m_sampleModel;
PythonSyntaxHighlighter* m_highlighter;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment