Skip to content

Commit

Permalink
TechDraw: [skip] fixes for balloon feature:
Browse files Browse the repository at this point in the history
* reimplement ViewProviderBalloon::setupContextMenu() to show item to start editing it
+ fix TaskBalloon::accept() and TaskBalloon::reject()
  • Loading branch information
wwmayer committed Feb 12, 2021
1 parent 84b8282 commit bb0d75b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
27 changes: 13 additions & 14 deletions src/Mod/TechDraw/Gui/TaskBalloon.cpp
Expand Up @@ -50,6 +50,7 @@
#include "QGIViewBalloon.h"
#include "ViewProviderBalloon.h"
#include "TaskBalloon.h"
#include "ui_TaskBalloon.h"

using namespace Gui;
using namespace TechDraw;
Expand Down Expand Up @@ -115,26 +116,24 @@ TaskBalloon::~TaskBalloon()

bool TaskBalloon::accept()
{
m_parent->dvBalloon->Text.setValue(ui->leText->text().toUtf8().constData());
App::Color ac;
ac.setValue<QColor>(ui->textColor->color());
m_balloonVP->Color.setValue(ac);
m_balloonVP->Fontsize.setValue(ui->qsbFontSize->value().getValue());
m_parent->dvBalloon->ShapeScale.setValue(ui->qsbShapeScale->value().getValue());
m_parent->dvBalloon->EndType.setValue(ui->comboEndSymbol->currentIndex());
m_parent->dvBalloon->EndTypeScale.setValue(ui->qsbSymbolScale->value().getValue());
m_parent->dvBalloon->BubbleShape.setValue(ui->comboBubbleShape->currentIndex());
m_balloonVP->LineVisible.setValue(ui->comboLineVisible->currentIndex());
m_balloonVP->LineWidth.setValue(ui->qsbLineWidth->value().getValue());
m_parent->dvBalloon->KinkLength.setValue(ui->qsbKinkLength->value().getValue());
m_parent->updateView(true);
Gui::Document* doc = m_balloonVP->getDocument();
m_balloonVP->getObject()->purgeTouched();
doc->commitCommand();
doc->resetEdit();

return true;
}

bool TaskBalloon::reject()
{
return false;
Gui::Document* doc = m_balloonVP->getDocument();
doc->abortCommand();
recomputeFeature();
m_parent->updateView(true);
m_balloonVP->getObject()->purgeTouched();
doc->resetEdit();

return true;
}

void TaskBalloon::recomputeFeature()
Expand Down
5 changes: 1 addition & 4 deletions src/Mod/TechDraw/Gui/TaskBalloon.h
Expand Up @@ -27,16 +27,13 @@
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>

#include <Mod/TechDraw/Gui/ui_TaskBalloon.h>

#include "QGIViewBalloon.h"
#include "ViewProviderBalloon.h"

class Ui_TaskBalloon;

namespace TechDrawGui
{

class Ui_TaskBalloon;
class TaskBalloon : public QWidget
{
Q_OBJECT
Expand Down
36 changes: 30 additions & 6 deletions src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp
Expand Up @@ -26,6 +26,8 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <QAction>
# include <QMenu>
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......
Expand All @@ -38,6 +40,7 @@
#include <App/DocumentObject.h>

#include <Gui/Application.h>
#include <Gui/ActionFunction.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
Expand Down Expand Up @@ -101,6 +104,33 @@ std::vector<std::string> ViewProviderBalloon::getDisplayModes(void) const
return StrList;
}

bool ViewProviderBalloon::doubleClicked(void)
{
startDefaultEditMode();
return true;
}

void ViewProviderBalloon::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
QAction* act = menu->addAction(QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue())));
act->setData(QVariant((int)ViewProvider::Default));
func->trigger(act, boost::bind(&ViewProviderBalloon::startDefaultEditMode, this));

ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
}

void ViewProviderBalloon::startDefaultEditMode()
{
QString text = QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue()));
Gui::Command::openCommand(text.toUtf8());

Gui::Document* document = this->getDocument();
if (document) {
document->setEdit(this, ViewProvider::Default);
}
}

bool ViewProviderBalloon::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
Expand Down Expand Up @@ -130,12 +160,6 @@ void ViewProviderBalloon::unsetEdit(int ModNum)
}
}

bool ViewProviderBalloon::doubleClicked(void)
{
setEdit(ViewProvider::Default);
return true;
}

void ViewProviderBalloon::updateData(const App::Property* p)
{
ViewProviderDrawingView::updateData(p);
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderBalloon.h
Expand Up @@ -58,6 +58,7 @@ class TechDrawGuiExport ViewProviderBalloon : public ViewProviderDrawingView
virtual std::vector<std::string> getDisplayModes(void) const;
virtual void updateData(const App::Property*);
virtual void onChanged(const App::Property* p);
virtual void setupContextMenu(QMenu*, QObject*, const char*);
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
virtual bool doubleClicked(void);
Expand All @@ -68,6 +69,8 @@ class TechDrawGuiExport ViewProviderBalloon : public ViewProviderDrawingView
protected:
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);

private:
void startDefaultEditMode();
};

} // namespace TechDrawGui
Expand Down

1 comment on commit bb0d75b

@donovaly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. however, now neither the Cancel button is respected and undo is broken.
To test:

  1. create a balloon
  2. double-click on the balloon in the drawing and change in the dialog the fontsize
  3. press Cancel
    -> the fontsize is changed nevertheless

now double-click onto the balloon again, change the fontsize and press OK
-> you cannot undo the change

Please sign in to comment.