Skip to content

Commit

Permalink
Merge pull request #5173 from nyalldawson/model_crash_win
Browse files Browse the repository at this point in the history
[processing] Fix crash in modeler on Windows
  • Loading branch information
nyalldawson committed Sep 12, 2017
2 parents 9b8fad5 + cf16a82 commit 457709d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
28 changes: 16 additions & 12 deletions python/core/conversions.sip 100644 → 100755
Expand Up @@ -1213,38 +1213,42 @@ template<TYPE2>
if (!d)
return NULL;

const sipMappedType *qlist_type = sipFindMappedType("QList<TYPE2>");

// Set the dictionary elements.
QMap<QString, QList< TYPE2 > >::const_iterator i;

for (i = sipCpp->constBegin(); i != sipCpp->constEnd(); ++i)
{
QString *t1 = new QString(i.key());

PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj);

QList< TYPE2 > *t2 = new QList< TYPE2 >( i.value() );

PyObject *t2obj = sipConvertFromMappedType(t2, qlist_type, sipTransferObj);
// build list for dictionary value
QList< TYPE2 > sourceList = i.value();
PyObject *t2list = PyList_New( sourceList.size() );
if ( t2list )
{
for ( int j = 0; j < sourceList.size(); j++ )
{
TYPE2 *t = new TYPE2(sourceList.at(j));
PyObject *lobj = sipConvertFromNewType(t, sipType_TYPE2, sipTransferObj);
PyList_SetItem( t2list, j, lobj );
}
}

if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
if (t1obj == NULL || t2list == NULL || PyDict_SetItem(d, t1obj, t2list) < 0)
{
Py_DECREF(d);

if (t1obj)
Py_DECREF(t1obj);

if (t2obj)
Py_DECREF(t2obj);
else
delete t2;
if (t2list)
Py_DECREF(t2list);

return NULL;
}

Py_DECREF(t1obj);
Py_DECREF(t2obj);
Py_DECREF(t2list);
}

return d;
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/processing/modeler/ModelerDialog.py 100644 → 100755
Expand Up @@ -588,17 +588,17 @@ def _addAlgorithm(self, alg, pos=None):
pass
if not dlg:
dlg = ModelerParametersDialog(alg, self.model)
dlg.exec_()
if dlg.alg is not None:
if dlg.exec_():
alg = dlg.createAlgorithm()
if pos is None:
dlg.alg.setPosition(self.getPositionForAlgorithmItem())
alg.setPosition(self.getPositionForAlgorithmItem())
else:
dlg.alg.setPosition(pos)
alg.setPosition(pos)
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
for i, out in enumerate(dlg.alg.modelOutputs()):
dlg.alg.modelOutput(out).setPosition(dlg.alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
ModelerGraphicItem.BOX_HEIGHT))
self.model.addChildAlgorithm(dlg.alg)
for i, out in enumerate(alg.modelOutputs()):
alg.modelOutput(out).setPosition(alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
ModelerGraphicItem.BOX_HEIGHT))
self.model.addChildAlgorithm(alg)
self.repaintModel()
self.hasChanged = True

Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/modeler/ModelerGraphicItem.py 100644 → 100755
Expand Up @@ -210,10 +210,10 @@ def editElement(self):
pass
if not dlg:
dlg = ModelerParametersDialog(self.element.algorithm(), self.model, self.element.childId())
dlg.exec_()
if dlg.alg is not None:
dlg.alg.setChildId(self.element.childId())
self.updateAlgorithm(dlg.alg)
if dlg.exec_():
alg = dlg.createAlgorithm()
alg.setChildId(self.element.childId())
self.updateAlgorithm(alg)
self.scene.dialog.repaintModel()

def updateAlgorithm(self, alg):
Expand Down
19 changes: 8 additions & 11 deletions python/plugins/processing/modeler/ModelerParametersDialog.py 100644 → 100755
Expand Up @@ -70,8 +70,6 @@ def __init__(self, alg, model, algName=None):
self.setModal(True)
# The algorithm to define in this dialog. It is an instance of GeoAlgorithm
self._alg = alg
# The resulting algorithm after the user clicks on OK. it is an instance of the container Algorithm class
self.alg = None
# The model this algorithm is going to be added to
self.model = model
# The name of the algorithm in the model, in case we are editing it and not defining it for the first time
Expand Down Expand Up @@ -348,21 +346,20 @@ def createAlgorithm(self):
dep_ids.append(availableDependencies[selected].childId()) # spellok
alg.setDependencies(dep_ids)

try:
self._alg.processBeforeAddingToModeler(alg, self.model)
except:
pass
#try:
# self._alg.processBeforeAddingToModeler(alg, self.model)
#except:
# pass

return alg

def okPressed(self):
self.alg = self.createAlgorithm()
if self.alg is not None:
self.close()
alg = self.createAlgorithm()
if alg is not None:
self.accept()

def cancelPressed(self):
self.alg = None
self.close()
self.reject()

def openHelp(self):
algHelp = self._alg.help()
Expand Down

0 comments on commit 457709d

Please sign in to comment.