Geometrize  1.0
An application for geometrizing images into geometric primitives
Public Member Functions | Private Member Functions | Private Attributes | List of all members
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl Class Reference
Collaboration diagram for geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl:
Collaboration graph
[legend]

Public Member Functions

 ImageTaskShapeScriptingPanelImpl (ImageTaskShapeScriptingPanel *pQ)
 
 ~ImageTaskShapeScriptingPanelImpl ()=default
 
ImageTaskShapeScriptingPanelImpl operator= (const ImageTaskShapeScriptingPanelImpl &)=delete
 
 ImageTaskShapeScriptingPanelImpl (const ImageTaskShapeScriptingPanelImpl &)=delete
 
void setImageTask (task::ImageTask *task)
 
void syncUserInterface ()
 
void onLanguageChange ()
 
std::map< std::string, std::string > getScripts () const
 

Private Member Functions

void populateUi ()
 
void buildPresetsMenuAndSelectPreset ()
 
void setupPreset (const int idx)
 
void setScriptModeEnabled (const bool enabled)
 
std::map< std::string, std::string > getDefaultScripts () const
 
dialog::ScriptEditorWidgetfindEditor (const std::string &functionName)
 
void setScripts (const std::map< std::string, std::string > &scripts)
 

Private Attributes

QMetaObject::Connection m_scriptEvaluationSucceededConnection {}
 
QMetaObject::Connection m_scriptEvaluationFailedConnection {}
 

Connection for the scripting panel to react when a script is successfully evaluated

More...
 
std::vector< ScriptEditorWidget * > m_editors
 

Connection for the scripting panel to react when a script fails to evaluate

More...
 
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
 
ImageTaskShapeScriptingPanelq
 
task::ImageTaskm_task {nullptr}
 

Constructor & Destructor Documentation

◆ ImageTaskShapeScriptingPanelImpl() [1/2]

geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ImageTaskShapeScriptingPanelImpl ( ImageTaskShapeScriptingPanel pQ)
inline
29  : ui{std::make_unique<Ui::ImageTaskShapeScriptingPanel>()}, q{pQ}
30  {
31  q->setWindowFlags(Qt::Window);
32  ui->setupUi(q);
33 
34  // Setup the scripting enable/disable checkbox
35  connect(ui->scriptsEnabledButton, &QCheckBox::toggled, [this](const bool enabled) {
36  emit q->signal_scriptingToggled(enabled);
37  });
38 
39  // Setup the reset scripting engine checkbox
40  connect(ui->resetScriptEngineButton, &QPushButton::pressed, [this]() {
41  for(ScriptEditorWidget* editor : m_editors) {
42  editor->resetCodeToDefault();
43  }
44  emit q->signal_scriptsReset();
45  });
46 
47  // Enable/disable scripting
48  connect(q, &geometrize::dialog::ImageTaskShapeScriptingPanel::signal_scriptingToggled, [this](const bool enableScripting) {
49  setScriptModeEnabled(enableScripting);
50  });
51 
52  // Resets the scripts to their original presets when reset is pressed
53  connect(ui->resetScriptEngineButton, &QPushButton::pressed, [this]() {
54  for(ScriptEditorWidget* editor : m_editors) {
55  editor->resetCodeToDefault();
56  }
57  });
58 
59  // Setup the actual actions that manipulate the image geometrization script functions
60  connect(q, &geometrize::dialog::ImageTaskShapeScriptingPanel::signal_scriptChanged, [this](const std::string& functionName, const std::string& code) {
61  if(m_task) {
62  m_task->getPreferences().setScript(functionName, code);
63  }
64  });
65 
66  // Handle changes to the script presets
67  connect(ui->scriptsPresetsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](const int idx) {
68  if(idx >= 0) {
69  setupPreset(idx);
70  }
71  });
72 
73  connect(ui->rescanScriptFoldersButton, &QPushButton::pressed, [this]() {
74  buildPresetsMenuAndSelectPreset();
75  });
76 
78  }

◆ ~ImageTaskShapeScriptingPanelImpl()

geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::~ImageTaskShapeScriptingPanelImpl ( )
default

◆ ImageTaskShapeScriptingPanelImpl() [2/2]

geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ImageTaskShapeScriptingPanelImpl ( const ImageTaskShapeScriptingPanelImpl )
delete

Member Function Documentation

◆ buildPresetsMenuAndSelectPreset()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::buildPresetsMenuAndSelectPreset ( )
inlineprivate
151  {
152  ui->scriptsPresetsComboBox->clear();
153 
154  // Populate the presets dropdown
155  // Set the menu to first index, slots will populate the panel with the default scripts
156  const QStringList presetOptions = QStringList()
157  << tr("Default Scripts")
158  << tr("Area Focus Scripts");
159 
160  ui->scriptsPresetsComboBox->addItems(presetOptions);
161  }

◆ findEditor()

dialog::ScriptEditorWidget* geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::findEditor ( const std::string &  functionName)
inlineprivate
217  {
218  auto it = std::find_if(m_editors.begin(), m_editors.end(), [&functionName](dialog::ScriptEditorWidget* editor) {
219  return editor->getFunctionName() == functionName;
220  });
221  if(it != m_editors.end()) {
222  return *it;
223  }
224  return nullptr;
225  }

◆ getDefaultScripts()

std::map<std::string, std::string> geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::getDefaultScripts ( ) const
inlineprivate
209  {
210  std::map<std::string, std::string> m;
211  for(ScriptEditorWidget* editor : m_editors) {
212  m[editor->getFunctionName()] = editor->getDefaultCode();
213  }
214  return m;
215  }

◆ getScripts()

std::map<std::string, std::string> geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::getScripts ( ) const
inline
135  {
136  std::map<std::string, std::string> m;
137  for(ScriptEditorWidget* editor : m_editors) {
138  m[editor->getFunctionName()] = editor->getCurrentCode();
139  }
140  return m;
141  }

◆ onLanguageChange()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::onLanguageChange ( )
inline
129  {
130  ui->retranslateUi(q);
131  populateUi();
132  }

◆ operator=()

ImageTaskShapeScriptingPanelImpl geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::operator= ( const ImageTaskShapeScriptingPanelImpl )
delete

◆ populateUi()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::populateUi ( )
inlineprivate
146  {
147 
148  }

◆ setImageTask()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setImageTask ( task::ImageTask task)
inline
84  {
85  m_task = task;
86 
87  if(m_task == nullptr) {
88  return;
89  }
90 
91  // Connect to the geometrizer that can update the widget when it tries to
93 
96  }
97  m_scriptEvaluationSucceededConnection = connect(&geometrizer, &geometrize::script::GeometrizerEngine::signal_scriptEvaluationSucceeded, [this](const std::string& functionName, const std::string& /*code*/) {
98  if(dialog::ScriptEditorWidget* editor = findEditor(functionName)) {
99  editor->onScriptEvaluationSucceeded();
100  }
101  });
102 
105  }
106  m_scriptEvaluationFailedConnection = connect(&geometrizer, &geometrize::script::GeometrizerEngine::signal_scriptEvaluationFailed, [this](const std::string& functionName, const std::string& /*code*/, const std::string& errorMessage) {
107  if(dialog::ScriptEditorWidget* editor = findEditor(functionName)) {
108  editor->onScriptEvaluationFailed(errorMessage);
109  }
110  });
111 
112  if(m_task) {
114 
115  const auto& scripts = getScripts();
116  for(const auto& script : scripts) {
117  m_task->getPreferences().setScript(script.first, script.second);
118  }
119  }
120  }
Here is the call graph for this function:

◆ setScriptModeEnabled()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setScriptModeEnabled ( const bool  enabled)
inlineprivate
196  {
197  if(m_task) {
199  }
200  ui->scriptsEnabledButton->setChecked(enabled);
201  ui->scriptsPresetsComboBox->setEnabled(enabled);
202  ui->rescanScriptFoldersButton->setEnabled(enabled);
203  ui->resetScriptEngineButton->setEnabled(enabled);
204  for(const auto& editor : m_editors) {
205  editor->setEnabled(enabled);
206  }
207  }

◆ setScripts()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setScripts ( const std::map< std::string, std::string > &  scripts)
inlineprivate
228  {
229  // Look for matching script editor widgets, and set their contents if found
230  for(const auto& script : scripts) {
231  if(dialog::ScriptEditorWidget* editor = findEditor(script.first)) {
232  if(script.second.length() == 0) {
233  editor->resetCodeToDefault();
234  } else {
235  editor->setCurrentCode(script.second);
236  }
237  }
238  }
239  }

◆ setupPreset()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setupPreset ( const int  idx)
inlineprivate
164  {
165  qDeleteAll(m_editors);
166  m_editors.clear();
167 
168  // Setup the script editor widgets
169  const auto scripts = [idx]() -> std::map<std::string, std::string> {
170  switch(idx) {
171  case 0:
173  case 1:
175  default:
176  assert(0 && "Bad scripts presets index");
177  return {{}};
178  }
179  }();
180 
181  for(const auto& item : scripts) {
182  ScriptEditorWidget* editor{new ScriptEditorWidget(item.first, item.first, item.second)};
183  m_editors.push_back(editor);
184  connect(editor, &ScriptEditorWidget::signal_scriptChanged, [this](ScriptEditorWidget* /*self*/, const std::string& functionName, const std::string& code) {
185  emit q->signal_scriptChanged(functionName, code);
186  });
187  ui->scriptEditorsContainer->addWidget(editor);
188  }
189 
190  if(m_task) {
191  m_task->getPreferences().setScripts(scripts);
192  }
193  }
Here is the call graph for this function:

◆ syncUserInterface()

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::syncUserInterface ( )
inline

Member Data Documentation

◆ m_editors

std::vector<ScriptEditorWidget*> geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_editors
private

Connection for the scripting panel to react when a script fails to evaluate

◆ m_scriptEvaluationFailedConnection

QMetaObject::Connection geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_scriptEvaluationFailedConnection {}
private

Connection for the scripting panel to react when a script is successfully evaluated

◆ m_scriptEvaluationSucceededConnection

QMetaObject::Connection geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_scriptEvaluationSucceededConnection {}
private

◆ m_task

task::ImageTask* geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_task {nullptr}
private

◆ q

ImageTaskShapeScriptingPanel* geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::q
private

◆ ui

std::unique_ptr<Ui::ImageTaskShapeScriptingPanel> geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ui
private

The documentation for this class was generated from the following file:
geometrize::preferences::ImageTaskPreferences::isScriptModeEnabled
bool isScriptModeEnabled() const
Definition: imagetaskpreferences.cpp:320
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::getScripts
std::map< std::string, std::string > getScripts() const
Definition: imagetaskshapescriptingpanel.cpp:134
geometrize::script::getPointerAreaOfInterestShapeMutatorScripts
std::map< std::string, std::string > getPointerAreaOfInterestShapeMutatorScripts()
getPointerAreaOfInterestScripts Gets a map of the scripts used for shape creation and mutation based ...
Definition: scriptutil.cpp:68
geometrize::preferences::ImageTaskPreferences::setScripts
void setScripts(const std::map< std::string, std::string > &scripts)
Definition: imagetaskpreferences.cpp:330
geometrize::preferences::ImageTaskPreferences::getScripts
std::map< std::string, std::string > getScripts() const
Definition: imagetaskpreferences.cpp:335
geometrize::dialog::ScriptEditorWidget::signal_scriptChanged
void signal_scriptChanged(ScriptEditorWidget *self, const std::string &functionName, const std::string &code)
signal_scriptChanged Signal emitted when the user change the script code of a function.
geometrize::script::getDefaultShapeMutatorScripts
std::map< std::string, std::string > getDefaultShapeMutatorScripts()
getDefaultScripts Gets a map of the default scripts used for shape creation and mutation in image tas...
Definition: scriptutil.cpp:63
geometrize::dialog::ImageTaskShapeScriptingPanel::signal_scriptingToggled
void signal_scriptingToggled(bool enabled)
geometrize::dialog::ImageTaskShapeScriptingPanel::signal_scriptsReset
void signal_scriptsReset()
geometrize::script::GeometrizerEngine::signal_scriptEvaluationSucceeded
void signal_scriptEvaluationSucceeded(const std::string &functionName, const std::string &code)
signal_scriptEvaluationSucceeded Signal dispatched when a script is successfully parsed/evaluated.
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::buildPresetsMenuAndSelectPreset
void buildPresetsMenuAndSelectPreset()
Definition: imagetaskshapescriptingpanel.cpp:150
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_scriptEvaluationSucceededConnection
QMetaObject::Connection m_scriptEvaluationSucceededConnection
Definition: imagetaskshapescriptingpanel.cpp:241
geometrize::preferences::ImageTaskPreferences::setScriptModeEnabled
void setScriptModeEnabled(bool enabled)
Definition: imagetaskpreferences.cpp:315
geometrize::dialog::ImageTaskShapeScriptingPanel::signal_scriptChanged
void signal_scriptChanged(const std::string &functionName, const std::string &code)
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_editors
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::q
ImageTaskShapeScriptingPanel * q
Definition: imagetaskshapescriptingpanel.cpp:245
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_scriptEvaluationFailedConnection
QMetaObject::Connection m_scriptEvaluationFailedConnection
Connection for the scripting panel to react when a script is successfully evaluated
Definition: imagetaskshapescriptingpanel.cpp:242
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_task
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::populateUi
void populateUi()
Definition: imagetaskshapescriptingpanel.cpp:145
geometrize::task::ImageTask::getGeometrizer
geometrize::script::GeometrizerEngine & getGeometrizer()
getGeometrizer Gets a reference to the script-based engine used to turn images into shapes.
Definition: imagetask.cpp:402
geometrize::script::GeometrizerEngine::signal_scriptEvaluationFailed
void signal_scriptEvaluationFailed(const std::string &functionName, const std::string &code, const std::string &errorMessage)
signal_scriptEvaluationFailed Signal dispatched when a script fails to parse/evaluate.
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ui
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::findEditor
dialog::ScriptEditorWidget * findEditor(const std::string &functionName)
Definition: imagetaskshapescriptingpanel.cpp:217
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setScriptModeEnabled
void setScriptModeEnabled(const bool enabled)
Definition: imagetaskshapescriptingpanel.cpp:195
geometrize::script::GeometrizerEngine
The GeometrizerEngine class encapsulates script-based setup and mutation methods for geometrizing sha...
Definition: geometrizerengine.h:58
geometrize::preferences::ImageTaskPreferences::setScript
void setScript(const std::string &scriptName, const std::string &code)
Definition: imagetaskpreferences.cpp:325
geometrize::task::ImageTask::getPreferences
geometrize::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:392
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::setScripts
void setScripts(const std::map< std::string, std::string > &scripts)
Definition: imagetaskshapescriptingpanel.cpp:227