Commit d9a7c387 authored by L. E. Segovia's avatar L. E. Segovia

Do not require ExprControlCollection on ExprEditor creation

parent 771f8b52
......@@ -65,8 +65,8 @@ ExprEditor::~ExprEditor() {
delete previewTimer;
}
ExprEditor::ExprEditor(QWidget* parent, ExprControlCollection* controls)
: QWidget(parent), _updatingText(0), errorHeight(0) {
ExprEditor::ExprEditor(QWidget* parent)
: QWidget(parent), controls(nullptr),_updatingText(0), errorHeight(0) {
// timers
controlRebuildTimer = new QTimer();
previewTimer = new QTimer();
......@@ -75,9 +75,6 @@ ExprEditor::ExprEditor(QWidget* parent, ExprControlCollection* controls)
setWindowTitle(tr("Expression Editor"));
setMinimumHeight(100);
// expression controls, we need for signal connections
this->controls = controls;
// make layout
QVBoxLayout* exprAndErrors = new QVBoxLayout;
exprAndErrors->setMargin(0);
......@@ -120,13 +117,34 @@ ExprEditor::ExprEditor(QWidget* parent, ExprControlCollection* controls)
connect(exprTe, SIGNAL(applyShortcut()), SLOT(sendApply()));
connect(exprTe, SIGNAL(nextError()), SLOT(nextError()));
connect(exprTe, SIGNAL(textChanged()), SLOT(exprChanged()));
connect(controls, SIGNAL(controlChanged(int)), SLOT(controlChanged(int)));
connect(controls, SIGNAL(insertString(const std::string&)), SLOT(insertStr(const std::string&)));
connect(controlRebuildTimer, SIGNAL(timeout()), SLOT(rebuildControls()));
connect(controlRebuildTimer, SIGNAL(timeout()), SLOT(sendPreview()));
connect(previewTimer, SIGNAL(timeout()), SLOT(sendPreview()));
}
ExprControlCollection* ExprEditor::controlCollectionWidget() const
{
return this->controls;
}
// expression controls, we need for signal connections
void ExprEditor::setControlCollectionWidget(ExprControlCollection* widget) {
if (this->controls)
{
disconnect(controlRebuildTimer, SIGNAL(timeout())),
disconnect(controls, SIGNAL(controlChanged(int)));
disconnect(controlRebuildTimer, SIGNAL(timeout()));
}
this->controls = widget;
if (this->controls)
{
connect(controlRebuildTimer, SIGNAL(timeout()), SLOT(rebuildControls()));
connect(controls, SIGNAL(controlChanged(int)), SLOT(controlChanged(int)));
connect(controls, SIGNAL(insertString(const std::string&)), SLOT(insertStr(const std::string&)));
}
}
void ExprEditor::selectError() {
int selected = errorWidget->currentRow();
QListWidgetItem* item = errorWidget->item(selected);
......
......@@ -32,8 +32,10 @@ class ExprEditor : public QWidget {
Q_OBJECT
public:
ExprEditor(QWidget* parent, ExprControlCollection* controls);
ExprEditor(QWidget* parent);
virtual ~ExprEditor();
virtual void setControlCollectionWidget(ExprControlCollection* widget);
ExprControlCollection* controlCollectionWidget() const;
public
Q_SLOTS:
......
......@@ -158,7 +158,8 @@ ImageEditorDialog::ImageEditorDialog(QWidget *parent) : QDialog(parent) {
scrollArea->setWidget(controls);
// Expression editor
_editor = new ExprEditor(this, controls);
_editor = new ExprEditor(this);
_editor->setControlCollectionWidget(controls);
// Expression browser
ExprBrowser *browser = new ExprBrowser(0, _editor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment