Skip to content

Commit

Permalink
Fix template field dialog multiple instances
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Jul 11, 2016
1 parent 277a00d commit 2ac560e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 39 deletions.
10 changes: 10 additions & 0 deletions src/Mod/TechDraw/Gui/DlgTemplateField.cpp
Expand Up @@ -66,4 +66,14 @@ std::string DlgTemplateField::getFieldContent()
return result.toStdString();
}

void DlgTemplateField::accept()
{
QDialog::accept();
}

void DlgTemplateField::reject()
{
QDialog::reject();
}

#include "moc_DlgTemplateField.cpp"
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/Gui/DlgTemplateField.h
Expand Up @@ -43,10 +43,11 @@ class DlgTemplateField : public QDialog, public Ui_dlgTemplateField
std::string getFieldContent();

public Q_SLOTS:
void accept();
void reject();

protected:
void changeEvent(QEvent *e);
//Ui_dlgTemplateField* ui;
};

} // namespace TechDrawGui
Expand Down
10 changes: 5 additions & 5 deletions src/Mod/TechDraw/Gui/DlgTemplateField.ui
Expand Up @@ -3,7 +3,7 @@
<class>TechDrawGui::dlgTemplateField</class>
<widget class="QDialog" name="TechDrawGui::dlgTemplateField">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
Expand Down Expand Up @@ -95,11 +95,11 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<x>209</x>
<y>126</y>
</hint>
<hint type="destinationlabel">
<x>193</x>
<x>209</x>
<y>79</y>
</hint>
</hints>
Expand All @@ -111,11 +111,11 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<x>209</x>
<y>126</y>
</hint>
<hint type="destinationlabel">
<x>193</x>
<x>209</x>
<y>79</y>
</hint>
</hints>
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/QGISVGTemplate.cpp
Expand Up @@ -48,7 +48,7 @@ using namespace TechDrawGui;

QGISVGTemplate::QGISVGTemplate(QGraphicsScene *scene, QWidget* srWidget)
: QGITemplate(scene),
upperLevelWidget(srWidget)
qgview(srWidget)
{
m_svgItem.setSharedRenderer(&m_svgRender);

Expand Down Expand Up @@ -167,7 +167,7 @@ void QGISVGTemplate::load(const QString &fileName)
double width = editClickBoxSize;
double height = editClickBoxSize;

TemplateTextField *item = new TemplateTextField(this, tmplte, nameMatch[1].str(), upperLevelWidget);
TemplateTextField *item = new TemplateTextField(this, tmplte, nameMatch[1].str(), qgview);
float pad = 1;
item->setRect(x - pad, -tmplte->getHeight() + y - height - pad,
width + 2 * pad, height + 2 * pad);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGISVGTemplate.h
Expand Up @@ -61,7 +61,7 @@ class TechDrawGuiExport QGISVGTemplate : public QGITemplate
protected:
void openFile(const QFile &file);
void load (const QString & fileName);
QWidget* upperLevelWidget; //for parenting dlgTemplateField
QWidget* qgview; //for parenting dlgTemplateField

protected:
TechDraw::DrawSVGTemplate * getSVGTemplate();
Expand Down
23 changes: 15 additions & 8 deletions src/Mod/TechDraw/Gui/TemplateTextField.cpp
Expand Up @@ -32,7 +32,6 @@
#include <Base/Console.h>

#include "TemplateTextField.h"
#include "DlgTemplateField.h"

//#include<QDebug>

Expand All @@ -41,11 +40,12 @@ using namespace TechDrawGui;
TemplateTextField::TemplateTextField(QGraphicsItem*parent,
TechDraw::DrawTemplate *myTmplte,
const std::string &myFieldName,
QWidget* upperWidget)
QWidget* qgview)
: QGraphicsRectItem(parent),
ui(nullptr),
tmplte(myTmplte),
fieldNameStr(myFieldName),
dlgOwner(upperWidget)
dlgOwner(qgview)
{
}

Expand All @@ -54,11 +54,8 @@ TemplateTextField::~TemplateTextField()
{
}

void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event)
void TemplateTextField::execDialog()
{
DlgTemplateField* ui = new DlgTemplateField(dlgOwner);
ui->setFieldName(fieldNameStr);
ui->setFieldContent(tmplte->EditableTexts[fieldNameStr]);
int uiCode = ui->exec();
std::string newContent = "";
if(uiCode == QDialog::Accepted) {
Expand All @@ -69,5 +66,15 @@ void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event)
tmplte->EditableTexts.setValue(fieldNameStr, newContent);
}
}
ui->deleteLater();
ui = nullptr; //ui memory will be release by ui's parent Widget
}

void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!ui) {
ui = new DlgTemplateField(dlgOwner);
ui->setFieldName(fieldNameStr);
ui->setFieldContent(tmplte->EditableTexts[fieldNameStr]);
execDialog();
}
}
44 changes: 22 additions & 22 deletions src/Mod/TechDraw/Gui/TemplateTextField.h
Expand Up @@ -27,12 +27,9 @@

#include <QGraphicsRectItem>

#include "DlgTemplateField.h"
#include "../App/DrawTemplate.h"

QT_BEGIN_NAMESPACE
class QGI;
QT_END_NAMESPACE

namespace TechDrawGui
{
/// QGraphicsRectItem-derived class for the text fields in title blocks
Expand All @@ -42,28 +39,31 @@ namespace TechDrawGui
* Property in the Drawing's template can be modified.
* Dear English, I'm sorry.
*/
class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem
{
public:
TemplateTextField(QGraphicsItem*parent,
TechDraw::DrawTemplate *myTmplte,
const std::string &myFieldName,
QWidget* upperWidget=0);
class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem
{
public:
TemplateTextField(QGraphicsItem*parent,
TechDraw::DrawTemplate *myTmplte,
const std::string &myFieldName,
QWidget* upperWidget=0);

~TemplateTextField();

~TemplateTextField();
enum {Type = QGraphicsItem::UserType + 160};
int type() const { return Type;}

enum {Type = QGraphicsItem::UserType + 160};
int type() const { return Type;}

/// Returns the field name that this TemplateTextField represents
std::string fieldName() const { return fieldNameStr; }

/// Returns the field name that this TemplateTextField represents
std::string fieldName() const { return fieldNameStr; }
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
TechDraw::DrawTemplate *tmplte;
std::string fieldNameStr;
QWidget* dlgOwner;
};
protected:
void execDialog(void);
DlgTemplateField* ui;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
TechDraw::DrawTemplate *tmplte;
std::string fieldNameStr;
QWidget* dlgOwner;
};
} // namespace TechDrawGui

#endif // #ifndef DRAWINGGUI_TEMPLATETEXTFIELD_H

0 comments on commit 2ac560e

Please sign in to comment.