Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
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

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]() {
75  });
76 
78  }
void signal_scriptChanged(const std::string &functionName, const std::string &code)
geometrize::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:330
void setScriptModeEnabled(const bool enabled)
Definition: imagetaskshapescriptingpanel.cpp:195
ImageTaskShapeScriptingPanel * q
Definition: imagetaskshapescriptingpanel.cpp:245
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
void setScript(const std::string &scriptName, const std::string &code)
Definition: imagetaskpreferences.cpp:252
void buildPresetsMenuAndSelectPreset()
Definition: imagetaskshapescriptingpanel.cpp:150
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
void setupPreset(const int idx)
Definition: imagetaskshapescriptingpanel.cpp:163
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::~ImageTaskShapeScriptingPanelImpl ( )
default
geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ImageTaskShapeScriptingPanelImpl ( const ImageTaskShapeScriptingPanelImpl )
delete

Member Function Documentation

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  }
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
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  }
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
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  }
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
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  }
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::onLanguageChange ( )
inline
129  {
130  ui->retranslateUi(q);
131  populateUi();
132  }
ImageTaskShapeScriptingPanel * q
Definition: imagetaskshapescriptingpanel.cpp:245
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
void populateUi()
Definition: imagetaskshapescriptingpanel.cpp:145
ImageTaskShapeScriptingPanelImpl geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::operator= ( const ImageTaskShapeScriptingPanelImpl )
delete
void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::populateUi ( )
inlineprivate
146  {
147 
148  }
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  }
dialog::ScriptEditorWidget * findEditor(const std::string &functionName)
Definition: imagetaskshapescriptingpanel.cpp:217
The GeometrizerEngine class encapsulates script-based setup and mutation methods for geometrizing sha...
Definition: geometrizerengine.h:57
std::map< std::string, std::string > getScripts() const
Definition: imagetaskshapescriptingpanel.cpp:134
geometrize::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:330
void setScriptModeEnabled(const bool enabled)
Definition: imagetaskshapescriptingpanel.cpp:195
bool isScriptModeEnabled() const
Definition: imagetaskpreferences.cpp:247
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
void setScript(const std::string &scriptName, const std::string &code)
Definition: imagetaskpreferences.cpp:252
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::script::GeometrizerEngine & getGeometrizer()
getGeometrizer Gets a reference to the script-based engine used to turn images into shapes...
Definition: imagetask.cpp:340
QMetaObject::Connection m_scriptEvaluationSucceededConnection
Definition: imagetaskshapescriptingpanel.cpp:241
void signal_scriptEvaluationSucceeded(const std::string &functionName, const std::string &code)
signal_scriptEvaluationSucceeded Signal dispatched when a script is successfully parsed/evaluated.
QMetaObject::Connection m_scriptEvaluationFailedConnection
Connection for the scripting panel to react when a script is successfully evaluated ...
Definition: imagetaskshapescriptingpanel.cpp:242

Here is the call graph for this function:

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  }
geometrize::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:330
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
void setScriptModeEnabled(bool enabled)
Definition: imagetaskpreferences.cpp:242
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  }
dialog::ScriptEditorWidget * findEditor(const std::string &functionName)
Definition: imagetaskshapescriptingpanel.cpp:217
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  }
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
void signal_scriptChanged(const std::string &functionName, const std::string &code)
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::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:330
ImageTaskShapeScriptingPanel * q
Definition: imagetaskshapescriptingpanel.cpp:245
std::unique_ptr< Ui::ImageTaskShapeScriptingPanel > ui
Definition: imagetaskshapescriptingpanel.cpp:244
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
std::vector< ScriptEditorWidget * > m_editors
Connection for the scripting panel to react when a script fails to evaluate
Definition: imagetaskshapescriptingpanel.cpp:243
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
void setScripts(const std::map< std::string, std::string > &scripts)
Definition: imagetaskpreferences.cpp:257

Here is the call graph for this function:

void geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::syncUserInterface ( )
inline
123  {
126  }
geometrize::preferences::ImageTaskPreferences & getPreferences()
getPreferences Gets a reference to the current preferences of this task.
Definition: imagetask.cpp:330
void setScriptModeEnabled(const bool enabled)
Definition: imagetaskshapescriptingpanel.cpp:195
bool isScriptModeEnabled() const
Definition: imagetaskpreferences.cpp:247
task::ImageTask * m_task
Definition: imagetaskshapescriptingpanel.cpp:246
void setScripts(const std::map< std::string, std::string > &scripts)
Definition: imagetaskshapescriptingpanel.cpp:227
std::map< std::string, std::string > getScripts() const
Definition: imagetaskpreferences.cpp:262

Member Data Documentation

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

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

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

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

QMetaObject::Connection geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_scriptEvaluationSucceededConnection {}
private
task::ImageTask* geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::m_task {nullptr}
private
ImageTaskShapeScriptingPanel* geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::q
private
std::unique_ptr<Ui::ImageTaskShapeScriptingPanel> geometrize::dialog::ImageTaskShapeScriptingPanel::ImageTaskShapeScriptingPanelImpl::ui
private

The documentation for this class was generated from the following file: