Skip to content

Commit

Permalink
bad practice: never use ptr->lock()->*
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Jun 28, 2017
1 parent a3ff3ab commit 59fc3de
Show file tree
Hide file tree
Showing 13 changed files with 873 additions and 186 deletions.
724 changes: 598 additions & 126 deletions Engine/OfxParamInstance.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Gui/Gui20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ Gui::removeViewerTab(ViewerTab* tab,
bool deleteData)
{
assert(tab);
if (!tab) {
throw std::logic_error("");
}
unregisterTab(tab);

if (tab == _imp->_activeViewer) {
Expand Down
36 changes: 30 additions & 6 deletions Gui/KnobGuiBool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ KnobGuiBool::removeSpecificGui()
void
KnobGuiBool::updateGUI(int /*dimension*/)
{
_checkBox->setChecked( _knob.lock()->getValue(0) );
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
_checkBox->setChecked( knob->getValue(0) );
}

void
Expand Down Expand Up @@ -268,7 +272,11 @@ KnobGuiBool::reflectAnimationLevel(int /*dimension*/,
void
KnobGuiBool::onLabelChangedInternal()
{
const std::string& label = _knob.lock()->getLabel();
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
const std::string& label = knob->getLabel();

if ( (label == "R") || (label == "r") || (label == "red") ) {
QColor color;
Expand Down Expand Up @@ -298,13 +306,21 @@ KnobGuiBool::onLabelClicked(bool b)
return;
}
_checkBox->setChecked(b);
pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), _knob.lock()->getValue(0), b, 0, false) );
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), knob->getValue(0), b, 0, false) );
}

void
KnobGuiBool::onCheckBoxStateChanged(bool b)
{
pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), _knob.lock()->getValue(0), b, 0, false) );
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), knob->getValue(0), b, 0, false) );
}

void
Expand Down Expand Up @@ -351,7 +367,11 @@ void
KnobGuiBool::reflectExpressionState(int /*dimension*/,
bool hasExpr)
{
bool isEnabled = _knob.lock()->isEnabled(0);
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
bool isEnabled = knob->isEnabled(0);

_checkBox->setAnimation(3);
_checkBox->setReadOnly(hasExpr || !isEnabled);
Expand All @@ -362,7 +382,11 @@ KnobGuiBool::updateToolTip()
{
if ( hasToolTip() ) {
QString tt = toolTip();
for (int i = 0; i < _knob.lock()->getDimension(); ++i) {
boost::shared_ptr<KnobBool> knob = _knob.lock();
if (!knob) {
return;
}
for (int i = 0; i < knob->getDimension(); ++i) {
_checkBox->setToolTip( tt );
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gui/KnobGuiButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ KnobGuiButton::emitValueChanged(bool clicked)
_button->setDown(clicked);
_button->setChecked(clicked);

pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), _knob.lock()->getValue(), clicked, 0, false) );
pushUndoCommand( new KnobUndoCommand<bool>(shared_from_this(), k->getValue(), clicked, 0, false) );
} else {
k->trigger();
}
Expand Down
30 changes: 25 additions & 5 deletions Gui/KnobGuiChoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ void
KnobGuiChoice::createWidget(QHBoxLayout* layout)
{
_comboBox = new KnobComboBox( shared_from_this(), 0, layout->parentWidget() );
_comboBox->setCascading( _knob.lock()->isCascading() );
boost::shared_ptr<KnobChoice> knob = _knob.lock();
if (!knob) {
return;
}
_comboBox->setCascading( knob->isCascading() );
onEntriesPopulated();

QObject::connect( _comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)) );
Expand All @@ -244,7 +248,11 @@ void
KnobGuiChoice::onCurrentIndexChanged(int i)
{
setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, QString() );
pushUndoCommand( new KnobUndoCommand<int>(shared_from_this(), _knob.lock()->getValue(0), i, 0, false, 0) );
boost::shared_ptr<KnobChoice> knob = _knob.lock();
if (!knob) {
return;
}
pushUndoCommand( new KnobUndoCommand<int>(shared_from_this(), knob->getValue(0), i, 0, false, 0) );
}

void
Expand Down Expand Up @@ -367,7 +375,11 @@ KnobGuiChoice::onItemNewSelected()

return;
}
KnobHolder* holder = _knob.lock()->getHolder();
boost::shared_ptr<KnobChoice> knob = _knob.lock();
if (!knob) {
return;
}
KnobHolder* holder = knob->getHolder();
assert(holder);
EffectInstance* effect = dynamic_cast<EffectInstance*>(holder);
assert(effect);
Expand All @@ -385,7 +397,11 @@ KnobGuiChoice::reflectExpressionState(int /*dimension*/,
bool hasExpr)
{
_comboBox->setAnimation(3);
bool isEnabled = _knob.lock()->isEnabled(0);
boost::shared_ptr<KnobChoice> knob = _knob.lock();
if (!knob) {
return;
}
bool isEnabled = knob->isEnabled(0);
_comboBox->setEnabled_natron(!hasExpr && isEnabled);
}

Expand Down Expand Up @@ -491,7 +507,11 @@ KnobGuiChoice::getKnob() const
void
KnobGuiChoice::reflectModificationsState()
{
bool hasModif = _knob.lock()->hasModifications();
boost::shared_ptr<KnobChoice> knob = _knob.lock();
if (!knob) {
return;
}
bool hasModif = knob->hasModifications();

_comboBox->setAltered(!hasModif);
}
Expand Down
24 changes: 20 additions & 4 deletions Gui/KnobGuiColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ KnobGuiColor::KnobGuiColor(KnobPtr knob,
, _colorLabel(0)
, _colorDialogButton(0)
, _lastColor( knob->getDimension() )
, _useSimplifiedUI( isViewerUIKnob() || _knob.lock()->isSimplified() )
, _useSimplifiedUI(true)
{
if (knob) {
boost::shared_ptr<KnobColor> k = _knob.lock();
_useSimplifiedUI = isViewerUIKnob() || ( k && k->isSimplified() );
}
}

void
Expand All @@ -224,7 +228,11 @@ KnobGuiColor::connectKnobSignalSlots()
void
KnobGuiColor::getIncrements(std::vector<double>* increments) const
{
int nDims = _knob.lock()->getDimension();
boost::shared_ptr<KnobColor> knob = _knob.lock();
if (!knob) {
return;
}
int nDims = knob->getDimension();

increments->resize(nDims);
for (int i = 0; i < nDims; ++i) {
Expand All @@ -235,7 +243,11 @@ KnobGuiColor::getIncrements(std::vector<double>* increments) const
void
KnobGuiColor::getDecimals(std::vector<int>* decimals) const
{
int nDims = _knob.lock()->getDimension();
boost::shared_ptr<KnobColor> knob = _knob.lock();
if (!knob) {
return;
}
int nDims = knob->getDimension();

decimals->resize(nDims);
for (int i = 0; i < nDims; ++i) {
Expand Down Expand Up @@ -524,7 +536,11 @@ KnobGuiColor::showColorDialog()
bool
KnobGuiColor::isAutoFoldDimensionsEnabled() const
{
return _knob.lock()->getDimension() == 3;
boost::shared_ptr<KnobColor> knob = _knob.lock();
if (!knob) {
return false;
}
return knob->getDimension() == 3;
}

NATRON_NAMESPACE_EXIT;
Expand Down
68 changes: 56 additions & 12 deletions Gui/KnobGuiFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ void
KnobGuiFile::reflectExpressionState(int /*dimension*/,
bool hasExpr)
{
bool isEnabled = _knob.lock()->isEnabled(0);
boost::shared_ptr<KnobFile> knob = _knob.lock();
if (!knob) {
return;
}
bool isEnabled = knob->isEnabled(0);

_lineEdit->setAnimation(3);
_lineEdit->setReadOnly_NoFocusRect(hasExpr || !isEnabled);
Expand Down Expand Up @@ -538,7 +542,11 @@ KnobGuiOutputFile::createWidget(QHBoxLayout* layout)
void
KnobGuiOutputFile::onButtonClicked()
{
open_file( _knob.lock()->isSequencesDialogEnabled() );
boost::shared_ptr<KnobOutputFile> knob = _knob.lock();
if (!knob) {
return;
}
open_file( knob->isSequencesDialogEnabled() );
}

void
Expand All @@ -555,9 +563,13 @@ KnobGuiOutputFile::onRewriteClicked()
void
KnobGuiOutputFile::open_file(bool openSequence)
{
boost::shared_ptr<KnobOutputFile> knob = _knob.lock();
if (!knob) {
return;
}
std::vector<std::string> filters;

if ( !_knob.lock()->isOutputImageFile() ) {
if ( !knob->isOutputImageFile() ) {
filters.push_back("*");
} else {
appPTR->getSupportedWriterFileFormats(&filters);
Expand Down Expand Up @@ -585,7 +597,11 @@ KnobGuiOutputFile::updateLastOpened(const QString &str)
void
KnobGuiOutputFile::updateGUI(int /*dimension*/)
{
_lineEdit->setText( QString::fromUtf8( _knob.lock()->getValue().c_str() ) );
boost::shared_ptr<KnobOutputFile> knob = _knob.lock();
if (!knob) {
return;
}
_lineEdit->setText( QString::fromUtf8( knob->getValue().c_str() ) );
}

void
Expand Down Expand Up @@ -720,7 +736,11 @@ void
KnobGuiOutputFile::reflectExpressionState(int /*dimension*/,
bool hasExpr)
{
bool isEnabled = _knob.lock()->isEnabled(0);
boost::shared_ptr<KnobOutputFile> knob = _knob.lock();
if (!knob) {
return;
}
bool isEnabled = knob->isEnabled(0);

_lineEdit->setAnimation(3);
_lineEdit->setReadOnly_NoFocusRect(hasExpr || !isEnabled);
Expand Down Expand Up @@ -810,7 +830,11 @@ KnobGuiPath::onOpenFileButtonClicked()
std::string dirPath = dialog.selectedDirectory();
updateLastOpened( QString::fromUtf8( dirPath.c_str() ) );

std::string oldValue = _knob.lock()->getValue();
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
std::string oldValue = knob->getValue();

pushUndoCommand( new KnobUndoCommand<std::string>( shared_from_this(), oldValue, dirPath ) );
}
Expand Down Expand Up @@ -974,7 +998,11 @@ KnobGuiPath::_show()
void
KnobGuiPath::setEnabled()
{
if ( _knob.lock()->isMultiPath() ) {
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
if ( knob->isMultiPath() ) {
KnobGuiTable::setEnabled();
} else {
bool enabled = getKnob()->isEnabled(0);
Expand All @@ -987,7 +1015,11 @@ void
KnobGuiPath::setReadOnly(bool readOnly,
int dimension)
{
if ( _knob.lock()->isMultiPath() ) {
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
if ( knob->isMultiPath() ) {
KnobGuiTable::setReadOnly(readOnly, dimension);
} else {
_lineEdit->setReadOnly_NoFocusRect(readOnly);
Expand All @@ -1009,7 +1041,11 @@ KnobGuiPath::getKnob() const
void
KnobGuiPath::addRightClickMenuEntries(QMenu* menu)
{
if ( !_knob.lock()->isMultiPath() ) {
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
if ( !knob->isMultiPath() ) {
QAction* makeAbsoluteAction = new QAction(tr("Make absolute"), menu);
QObject::connect( makeAbsoluteAction, SIGNAL(triggered()), this, SLOT(onMakeAbsoluteTriggered()) );
makeAbsoluteAction->setToolTip( tr("Make the file-path absolute if it was previously relative to any project path") );
Expand Down Expand Up @@ -1074,7 +1110,11 @@ void
KnobGuiPath::reflectAnimationLevel(int /*dimension*/,
AnimationLevelEnum /*level*/)
{
if ( !_knob.lock()->isMultiPath() ) {
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
if ( !knob->isMultiPath() ) {
_lineEdit->setAnimation(0);
}
}
Expand All @@ -1086,7 +1126,7 @@ KnobGuiPath::reflectExpressionState(int /*dimension*/,
boost::shared_ptr<KnobPath> knob = _knob.lock();

if ( !knob->isMultiPath() ) {
bool isEnabled = _knob.lock()->isEnabled(0);
bool isEnabled = knob->isEnabled(0);
_lineEdit->setAnimation(3);
_lineEdit->setReadOnly_NoFocusRect(hasExpr || !isEnabled);
_openFileButton->setEnabled(!hasExpr || isEnabled);
Expand All @@ -1098,7 +1138,11 @@ KnobGuiPath::updateToolTip()
{
if ( hasToolTip() ) {
QString tt = toolTip();
if ( !_knob.lock()->isMultiPath() ) {
boost::shared_ptr<KnobPath> knob = _knob.lock();
if (!knob) {
return;
}
if ( !knob->isMultiPath() ) {
_lineEdit->setToolTip(tt);
} else {
KnobGuiTable::updateToolTip();
Expand Down
12 changes: 10 additions & 2 deletions Gui/KnobGuiGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ KnobGuiGroup::createWidget(QHBoxLayout* layout)
if ( hasToolTip() ) {
_button->setToolTip( toolTip() );
}
_checked = _knob.lock()->getValue();
boost::shared_ptr<KnobGroup> knob = _knob.lock();
if (!knob) {
return;
}
_checked = knob->getValue();
_button->setFixedSize(NATRON_MEDIUM_BUTTON_SIZE, NATRON_MEDIUM_BUTTON_SIZE);
_button->setChecked(_checked);
QObject::connect( _button, SIGNAL(checked(bool)), this, SLOT(onCheckboxChecked(bool)) );
Expand Down Expand Up @@ -215,7 +219,11 @@ KnobGuiGroup::eventFilter(QObject */*target*/,
void
KnobGuiGroup::updateGUI(int /*dimension*/)
{
bool b = _knob.lock()->getValue(0);
boost::shared_ptr<KnobGroup> knob = _knob.lock();
if (!knob) {
return;
}
bool b = knob->getValue(0);

setCheckedInternal(b, false);
if (_button) {
Expand Down
Loading

0 comments on commit 59fc3de

Please sign in to comment.