Skip to content
Permalink
Browse files

More c++ ports

  • Loading branch information
nyalldawson committed Mar 6, 2020
1 parent df7dd5b commit 8845b535c5171226485c390e75617e65ced8fc70
@@ -46,7 +46,7 @@ Model designer dialog base class
QAction *actionExportImage();
QLineEdit *textName();
QLineEdit *textGroup();
QScrollArea *inputsScrollArea();
QTreeWidget *inputsTree();
QgsProcessingToolboxTreeView *algorithmsTree();

QgsMessageBar *messageBar();
@@ -29,18 +29,13 @@
QCoreApplication,
QDir,
QRectF,
QMimeData,
QPoint,
QPointF,
pyqtSignal,
QUrl)
from qgis.PyQt.QtWidgets import (QTreeWidget,
QMessageBox,
from qgis.PyQt.QtWidgets import (QMessageBox,
QFileDialog,
QTreeWidgetItem,
QDockWidget,
QWidget,
QVBoxLayout,
QToolButton,
QAction)
from qgis.PyQt.QtGui import QIcon
@@ -53,13 +48,9 @@
QgsProcessingModelAlgorithm,
QgsProcessingModelParameter,
QgsProcessingParameterType,
QgsExpressionContextScope,
QgsExpressionContext
)
from qgis.gui import (QgsDockWidget,
QgsProcessingToolboxProxyModel,
from qgis.gui import (QgsProcessingToolboxProxyModel,
QgsProcessingParameterDefinitionDialog,
QgsVariableEditorWidget,
QgsProcessingParameterWidgetContext,
QgsModelGraphicsScene,
QgsModelDesignerDialog)
@@ -124,16 +115,6 @@ def __init__(self, model=None, parent=None):
super().__init__(parent)
self._model = None

self.scrollAreaWidgetContents_2 = QWidget()
self.verticalLayout = QVBoxLayout(self.scrollAreaWidgetContents_2)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(0)
self.inputsTree = QTreeWidget(self.scrollAreaWidgetContents_2)
self.inputsTree.setAlternatingRowColors(True)
self.inputsTree.header().setVisible(False)
self.verticalLayout.addWidget(self.inputsTree)
self.inputsScrollArea().setWidget(self.scrollAreaWidgetContents_2)

if iface is not None:
self.toolbar().setIconSize(iface.iconSize())
self.setStyleSheet(iface.mainWindow().styleSheet())
@@ -156,22 +137,11 @@ def __init__(self, model=None, parent=None):
self.view().ensureVisible(0, 0, 10, 10)
self.view().scale(QgsApplication.desktop().logicalDpiX() / 96, QgsApplication.desktop().logicalDpiX() / 96)

def _mimeDataInput(items):
mimeData = QMimeData()
text = items[0].data(0, Qt.UserRole)
mimeData.setText(text)
return mimeData

self.inputsTree.mimeData = _mimeDataInput

self.inputsTree.setDragDropMode(QTreeWidget.DragOnly)
self.inputsTree.setDropIndicatorShown(True)

self.algorithms_model = ModelerToolboxModel(self, QgsApplication.processingRegistry())
self.algorithmsTree().setToolboxProxyModel(self.algorithms_model)

# Connect signals and slots
self.inputsTree.doubleClicked.connect(self._addInput)
self.inputsTree().doubleClicked.connect(self._addInput)

self.actionOpen().triggered.connect(self.openModel)
self.actionSave().triggered.connect(self.save)
@@ -367,7 +337,7 @@ def componentChanged(self):
self.hasChanged = True

def _addInput(self):
item = self.inputsTree.currentItem()
item = self.inputsTree().currentItem()
param = item.data(0, Qt.UserRole)
self.addInput(param)

@@ -465,7 +435,7 @@ def fillInputsTree(self):
paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled)
paramItem.setToolTip(0, param.description())
parametersItem.addChild(paramItem)
self.inputsTree.addTopLevelItem(parametersItem)
self.inputsTree().addTopLevelItem(parametersItem)
parametersItem.setExpanded(True)

def addAlgorithm(self, alg_id, pos=None):
@@ -256,6 +256,7 @@ SET(QGIS_GUI_SRCS
processing/models/qgsmodelarrowitem.cpp
processing/models/qgsmodelcomponentgraphicitem.cpp
processing/models/qgsmodeldesignerdialog.cpp
processing/models/qgsmodeldesignerinputstreewidget.cpp
processing/models/qgsmodelgraphicitem.cpp
processing/models/qgsmodelgraphicsscene.cpp
processing/models/qgsmodelgraphicsview.cpp
@@ -889,6 +890,7 @@ SET(QGIS_GUI_HDRS
processing/models/qgsmodelarrowitem.h
processing/models/qgsmodelcomponentgraphicitem.h
processing/models/qgsmodeldesignerdialog.h
processing/models/qgsmodeldesignerinputstreewidget.h
processing/models/qgsmodelgraphicitem.h
processing/models/qgsmodelgraphicsscene.h
processing/models/qgsmodelgraphicsview.h
@@ -32,6 +32,7 @@

///@cond NOT_STABLE


QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
{
@@ -54,6 +55,11 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
mAlgorithmSearchEdit->setPlaceholderText( tr( "Search…" ) );
connect( mAlgorithmSearchEdit, &QgsFilterLineEdit::textChanged, mAlgorithmsTree, &QgsProcessingToolboxTreeView::setFilterString );

mInputsTreeWidget->header()->setVisible( false );
mInputsTreeWidget->setAlternatingRowColors( true );
mInputsTreeWidget->setDragDropMode( QTreeWidget::DragOnly );
mInputsTreeWidget->setDropIndicatorShown( true );

mNameEdit->setPlaceholderText( tr( "Enter model name here" ) );
mGroupEdit->setPlaceholderText( tr( "Enter group name here" ) );

@@ -271,3 +277,4 @@ void QgsModelDesignerDialog::exportAsPython()


///@endcond

@@ -54,7 +54,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
QAction *actionExportImage() { return mActionExportImage; }
QLineEdit *textName() { return mNameEdit; }
QLineEdit *textGroup() { return mGroupEdit; }
QScrollArea *inputsScrollArea() { return mInputsScrollArea; }
QTreeWidget *inputsTree() { return mInputsTreeWidget; }
QgsProcessingToolboxTreeView *algorithmsTree() { return mAlgorithmsTree; }

QgsMessageBar *messageBar() { return mMessageBar; }
@@ -0,0 +1,40 @@
/***************************************************************************
qgsmodeldesignerinputstreewidget.cpp
------------------------
Date : March 2020
Copyright : (C) 2020 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmodeldesignerinputstreewidget.h"

#include <QMimeData>

///@cond NOT_STABLE

QgsModelDesignerInputsTreeWidget::QgsModelDesignerInputsTreeWidget( QWidget *parent )
: QTreeWidget( parent )
{

}

QMimeData *QgsModelDesignerInputsTreeWidget::mimeData( const QList<QTreeWidgetItem *> items ) const
{
if ( items.empty() )
return nullptr;

std::unique_ptr< QMimeData > res = qgis::make_unique< QMimeData >();
const QString text = items.value( 0 )->data( 0, Qt::UserRole ).toString();
res->setText( text );
return res.release();
}

///@endcond

@@ -0,0 +1,49 @@
/***************************************************************************
qgsmodeldesignerinputstreewidget.h
------------------------
Date : March 2020
Copyright : (C) 2020 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMODELDESIGNERINPUTSTREEWIDGET_H
#define QGSMODELDESIGNERINPUTSTREEWIDGET_H

#include "qgis.h"
#include "qgis_gui.h"
#include <QTreeWidget>

class QMimeData;

#define SIP_NO_FILE

///@cond NOT_STABLE

/**
* \ingroup gui
* \brief QTreeWidget subclass for use in the model designer as an input list.
* \warning Not stable API
* \since QGIS 3.14
*/
class QgsModelDesignerInputsTreeWidget : public QTreeWidget
{
public:

/**
* Constructor for QgsModelDesignerInputsTreeWidget with the specified \a parent widget.
*/
explicit QgsModelDesignerInputsTreeWidget( QWidget *parent = nullptr );

QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
};

///@endcond

#endif // QGSMODELDESIGNERINPUTSTREEWIDGET_H
@@ -243,6 +243,29 @@
<height>70</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QgsModelDesignerInputsTreeWidget" name="mInputsTreeWidget">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
@@ -591,6 +614,11 @@
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsModelDesignerInputsTreeWidget</class>
<extends>QTreeWidget</extends>
<header>qgsmodeldesignerinputstreewidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../images/images.qrc"/>

0 comments on commit 8845b53

Please sign in to comment.
You can’t perform that action at this time.