Skip to content

Commit

Permalink
Make sure backdrops are restored correctly.
Browse files Browse the repository at this point in the history
Also fixed a crash on exit
  • Loading branch information
MrKepzie committed Aug 1, 2014
1 parent 440e2f8 commit 37729c1
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Global/GitVersion.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef NATRON_GITVERSION_H_
#define NATRON_GITVERSION_H_
#define GIT_BRANCH "workshop"
#define GIT_COMMIT "c04ce227f24bb38dd3f67cf8097b3983719b4551"
#define GIT_COMMIT "49d83ad512f556e1dbf7d63ce40c33e312007748"
#endif
15 changes: 12 additions & 3 deletions Gui/DockablePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ DockablePanel::DockablePanel(Gui* gui
}

DockablePanel::~DockablePanel(){
if (_imp->_nameLineEdit) {
QObject::disconnect(_imp->_nameLineEdit,SIGNAL(editingFinished()),this,SLOT(onLineEditNameEditingFinished()));
}

delete _imp->_undoStack;

///Delete the knob gui if they weren't before
Expand All @@ -430,6 +428,14 @@ DockablePanel::~DockablePanel(){
// }
}

void DockablePanel::onGuiClosing()
{
if (_imp->_nameLineEdit) {
QObject::disconnect(_imp->_nameLineEdit,SIGNAL(editingFinished()),this,SLOT(onLineEditNameEditingFinished()));
}
_imp->_gui = 0;
}

KnobHolder* DockablePanel::getHolder() const
{
return _imp->_holder;
Expand Down Expand Up @@ -948,6 +954,9 @@ void DockablePanel::showHelp(){

void DockablePanel::setClosed(bool c)
{
if (!_imp->_gui){
return;
}
if (_imp->_floating) {
floatPanel();
}
Expand Down
2 changes: 2 additions & 0 deletions Gui/DockablePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class DockablePanel : public QFrame {

KnobHolder* getHolder() const;

void onGuiClosing();

public slots:

/*Internal slot, not meant to be called externally.*/
Expand Down
25 changes: 18 additions & 7 deletions Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ struct GuiPrivate {
void retranslateUi(QMainWindow *MainWindow);

void addToolButton(ToolButton* tool);

void notifyGuiClosing();

};

Expand Down Expand Up @@ -465,6 +467,18 @@ Gui::~Gui()
}
}

void GuiPrivate::notifyGuiClosing()
{
///This is to workaround an issue that when destroying a widget it calls the focusOut() handler hence can
///cause bad pointer dereference to the Gui object since we're destroying it.
for (std::list<ViewerTab*>::iterator it = _viewerTabs.begin(); it!=_viewerTabs.end(); ++it) {
(*it)->notifyAppClosing();
}
for (std::list<DockablePanel*>::iterator it = openedPanels.begin();it!=openedPanels.end(); ++it) {
(*it)->onGuiClosing();
}
}

bool Gui::closeInstance()
{
if (getApp()->getProject()->hasNodes()) {
Expand Down Expand Up @@ -513,11 +527,8 @@ void Gui::abortProject(bool quitApp)

assert(_imp->_appInstance);

///This is to workaround an issue that when destroying a widget it calls the focusOut() handler hence can
///cause bad pointer dereference to the Gui object since we're destroying it.
for (std::list<ViewerTab*>::iterator it = _imp->_viewerTabs.begin(); it!=_imp->_viewerTabs.end(); ++it) {
(*it)->notifyAppClosing();
}

_imp->notifyGuiClosing();
_imp->_appInstance->quit();
} else {
_imp->_appInstance->getProject()->closeProject();
Expand Down Expand Up @@ -2854,9 +2865,9 @@ void Gui::clearAllVisiblePanels()
}
}

NodeBackDrop* Gui::createBackDrop(bool requestedByLoad)
NodeBackDrop* Gui::createBackDrop(bool requestedByLoad,const NodeBackDropSerialization& serialization)
{
return _imp->_nodeGraphArea->createBackDrop(_imp->_layoutPropertiesBin,requestedByLoad);
return _imp->_nodeGraphArea->createBackDrop(_imp->_layoutPropertiesBin,requestedByLoad,serialization);
}


Expand Down
3 changes: 2 additions & 1 deletion Gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DockablePanel;
class NodeGraph;
class CurveEditor;
class Histogram;
class NodeBackDropSerialization;
class RotoGui;

//Natron engine
Expand Down Expand Up @@ -320,7 +321,7 @@ class Gui : public QMainWindow , public boost::noncopyable
void addVisibleDockablePanel(DockablePanel* panel);
void removeVisibleDockablePanel(DockablePanel* panel);

NodeBackDrop* createBackDrop(bool requestedByLoad) ;
NodeBackDrop* createBackDrop(bool requestedByLoad,const NodeBackDropSerialization& serialization) ;

std::list<ToolButton*> getToolButtonsOrdered() const;

Expand Down
3 changes: 2 additions & 1 deletion Gui/GuiAppInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Gui/NodeGraph.h"
#include "Gui/NodeGui.h"
#include "Gui/MultiInstancePanel.h"
#include "Gui/NodeBackDropSerialization.h"

#include "Engine/Project.h"
#include "Engine/EffectInstance.h"
Expand Down Expand Up @@ -481,7 +482,7 @@ void GuiAppInstance::onMaxPanelsOpenedChanged(int maxPanels)
void GuiAppInstance::createBackDrop()
{
///This function is not used when loading a project, rather we use the one directly in Gui (@see ProjectGui::load)
_imp->_gui->createBackDrop(false);
_imp->_gui->createBackDrop(false,NodeBackDropSerialization());
}

void GuiAppInstance::registerVideoEngineBeingAborted(VideoEngine* engine)
Expand Down
32 changes: 31 additions & 1 deletion Gui/NodeBackDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Gui/NodeGraph.h"
#include "Gui/GuiApplicationManager.h"
#include "Gui/KnobGuiTypes.h"
#include "Gui/NodeBackDropSerialization.h"

#define RESIZE_HANDLE_SIZE 20

Expand Down Expand Up @@ -84,6 +85,8 @@ struct NodeBackDropPrivate

void refreshLabelText(const QString& text);

void restoreFromSerialization(const NodeBackDropSerialization& serialization);

};

NodeBackDrop::NodeBackDrop(NodeGraph* dag,QGraphicsItem* parent)
Expand All @@ -98,7 +101,8 @@ NodeBackDrop::NodeBackDrop(NodeGraph* dag,QGraphicsItem* parent)

}

void NodeBackDrop::initialize(const QString& name,bool requestedByLoad,QVBoxLayout *dockContainer)
void NodeBackDrop::initialize(const QString& name,bool requestedByLoad,const NodeBackDropSerialization& serialization,
QVBoxLayout *dockContainer)
{

QString tooltip(tr("The node backdrop is useful to group nodes and identify them in the node graph. You can also "
Expand Down Expand Up @@ -149,6 +153,10 @@ void NodeBackDrop::initialize(const QString& name,bool requestedByLoad,QVBoxLayo
_imp->resizeHandle->setZValue(-7);


if (!serialization.isNull()) {
_imp->restoreFromSerialization(serialization);
}

///initialize knobs gui now
_imp->settingsPanel->initializeKnobs();

Expand Down Expand Up @@ -473,3 +481,25 @@ void NodeBackDrop::activate()
setActive(true);
setVisible(true);
}

void NodeBackDropPrivate::restoreFromSerialization(const NodeBackDropSerialization &serialization)
{
QPointF pos;
serialization.getPos(pos.rx(), pos.ry());
_publicInterface->setPos_mt_safe(pos);

int w,h;
serialization.getSize(w, h);
_publicInterface->resize(w, h);
float r,g,b;
serialization.getColor(r, g, b);
QColor color;
color.setRgbF(r, g, b);
_publicInterface->setCurrentColor(color);
_publicInterface->setName(serialization.getName().c_str());
boost::shared_ptr<String_Knob> labelKnob = _publicInterface->getLabelKnob();
assert(labelKnob);
labelKnob->clone(serialization.getLabelSerialization().get());
_publicInterface->refreshTextLabelFromKnob();

}
4 changes: 2 additions & 2 deletions Gui/NodeBackDrop.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class String_Knob;

class NodeGraph;
class DockablePanel;

class NodeBackDropSerialization;
struct NodeBackDropPrivate;
class NodeBackDrop : public QObject, public QGraphicsRectItem, public NamedKnobHolder
{
Expand All @@ -32,7 +32,7 @@ class NodeBackDrop : public QObject, public QGraphicsRectItem, public NamedKnobH

NodeBackDrop(NodeGraph* dag,QGraphicsItem* parent = 0);

void initialize(const QString& name,bool requestedByLoad,QVBoxLayout *dockContainer);
void initialize(const QString& name,bool requestedByLoad,const NodeBackDropSerialization& serialization,QVBoxLayout *dockContainer);

virtual ~NodeBackDrop();

Expand Down
3 changes: 2 additions & 1 deletion Gui/NodeBackDropSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Gui/NodeBackDrop.h"

NodeBackDropSerialization::NodeBackDropSerialization()
: posX(0),posY(0),width(0),height(0),name(),label(),r(0),g(0),b(0),selected(false)
: posX(0),posY(0),width(0),height(0),name(),label(),r(0),g(0),b(0),selected(false) , _isNull(true)
{
}

Expand All @@ -32,4 +32,5 @@ void NodeBackDropSerialization::initialize(const NodeBackDrop* n)
masterBackdropName = master->getName_mt_safe();
}
selected = n->getIsSelected();
_isNull = false;
}
4 changes: 4 additions & 0 deletions Gui/NodeBackDropSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class NodeBackDropSerialization
void getColor(float& red,float &green,float& blue) const { red = r; green = g; blue = b; }

bool isSelected() const { return selected; }

bool isNull() const { return _isNull; }
private:

double posX;
Expand All @@ -58,6 +60,7 @@ class NodeBackDropSerialization
float r,g,b;
std::string masterBackdropName;
bool selected;
bool _isNull;

friend class boost::serialization::access;
template<class Archive>
Expand Down Expand Up @@ -95,6 +98,7 @@ class NodeBackDropSerialization
if (version >= NODE_BACKDROP_INTRODUCES_SELECTED) {
ar & boost::serialization::make_nvp("Selected",selected);
}
_isNull = false;
}

BOOST_SERIALIZATION_SPLIT_MEMBER()
Expand Down
15 changes: 3 additions & 12 deletions Gui/NodeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2543,20 +2543,11 @@ NodeGraphPrivate::pasteBackdrop(const NodeBackDropSerialization& serialization,c
name.append(QString::number(no));
}

bd->initialize(name, true, _gui->getPropertiesLayout());
bd->initialize(name, true,serialization ,_gui->getPropertiesLayout());
_publicInterface->insertNewBackDrop(bd);
float r,g,b;
serialization.getColor(r,g,b);
QColor color;
color.setRgbF(r, g, b);
double x,y;
int w,h;
serialization.getPos(x, y);
serialization.getSize(w, h);
bd->setCurrentColor(color);
//bd->setPos_mt_safe(QPointF(x + w,y));
bd->setPos_mt_safe(QPointF(x,y) + offset);
bd->resize(w, h);
return bd;
}

Expand Down Expand Up @@ -2854,7 +2845,7 @@ NodeGraph::toggleConnectionHints()
appPTR->getCurrentSettings()->setConnectionHintsEnabled(!appPTR->getCurrentSettings()->isConnectionHintEnabled());
}

NodeBackDrop* NodeGraph::createBackDrop(QVBoxLayout *dockContainer,bool requestedByLoad)
NodeBackDrop* NodeGraph::createBackDrop(QVBoxLayout *dockContainer,bool requestedByLoad,const NodeBackDropSerialization& serialization)
{
QString name(NATRON_BACKDROP_NODE_NAME);
int no = _imp->_backdrops.size() + 1;
Expand All @@ -2865,7 +2856,7 @@ NodeBackDrop* NodeGraph::createBackDrop(QVBoxLayout *dockContainer,bool requeste
name += QString::number(no);
}
NodeBackDrop* bd = new NodeBackDrop(this,_imp->_root);
bd->initialize(name, requestedByLoad, dockContainer);
bd->initialize(name, requestedByLoad,serialization, dockContainer);
_imp->_backdrops.push_back(bd);
_imp->_undoStack->setActive();
if (!requestedByLoad) {
Expand Down
2 changes: 1 addition & 1 deletion Gui/NodeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NodeGraph: public QGraphicsView , public boost::noncopyable

void deleteNodePermanantly(boost::shared_ptr<NodeGui> n);

NodeBackDrop* createBackDrop(QVBoxLayout *dockContainer,bool requestedByLoad);
NodeBackDrop* createBackDrop(QVBoxLayout *dockContainer,bool requestedByLoad,const NodeBackDropSerialization& serialization);

///Returns true if it already exists
bool checkIfBackDropNameExists(const QString& n,const NodeBackDrop* bd) const;
Expand Down
19 changes: 2 additions & 17 deletions Gui/ProjectGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,8 @@ void ProjectGui::load(boost::archive::xml_iarchive& archive){
///now restore the backdrops
const std::list<NodeBackDropSerialization>& backdrops = obj.getBackdrops();
for (std::list<NodeBackDropSerialization>::const_iterator it = backdrops.begin(); it != backdrops.end(); ++it) {
NodeBackDrop* bd = _gui->createBackDrop(true);
QPointF pos;
it->getPos(pos.rx(), pos.ry());
bd->setPos_mt_safe(pos);

int w,h;
it->getSize(w, h);
bd->resize(w, h);
float r,g,b;
it->getColor(r, g, b);
QColor color;
color.setRgbF(r, g, b);
bd->setCurrentColor(color);
bd->setName(it->getName().c_str());
bd->getLabelKnob()->clone(it->getLabelSerialization().get());
bd->refreshTextLabelFromKnob();

NodeBackDrop* bd = _gui->createBackDrop(true,*it);

if (it->isSelected()) {
_gui->getNodeGraph()->selectBackDrop(bd, true);
}
Expand Down

0 comments on commit 37729c1

Please sign in to comment.