-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] add modeler GUI for enum parameter
- Loading branch information
1 parent
213fc55
commit ffa4b04
Showing
3 changed files
with
235 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
EnumModelerWidget.py | ||
--------------------- | ||
Date : May 2018 | ||
Copyright : (C) 2018 by Alexander Bruy | ||
Email : alexander dot bruy 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. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Alexander Bruy' | ||
__date__ = 'May 2018' | ||
__copyright__ = '(C) 2018, Alexander Bruy' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
import os | ||
|
||
from qgis.PyQt import uic | ||
from qgis.PyQt.QtCore import Qt | ||
from qgis.PyQt.QtGui import QStandardItemModel, QStandardItem | ||
|
||
from qgis.core import QgsApplication | ||
|
||
pluginPath = os.path.split(os.path.dirname(__file__))[0] | ||
WIDGET, BASE = uic.loadUiType( | ||
os.path.join(pluginPath, 'ui', 'enummodelerwidgetbase.ui')) | ||
|
||
|
||
class EnumModelerWidget(BASE, WIDGET): | ||
|
||
def __init__(self, parent=None): | ||
super(EnumModelerWidget, self).__init__(parent) | ||
self.setupUi(self) | ||
|
||
self.btnAdd.setIcon(QgsApplication.getThemeIcon('/symbologyAdd.svg')) | ||
self.btnRemove.setIcon(QgsApplication.getThemeIcon('/symbologyRemove.svg')) | ||
self.btnClear.setIcon(QgsApplication.getThemeIcon('/mIconClearText.svg')) | ||
|
||
self.btnAdd.clicked.connect(self.addItem) | ||
self.btnRemove.clicked.connect(lambda: self.removeItems()) | ||
self.btnClear.clicked.connect(lambda: self.removeItems(True)) | ||
|
||
self.lstItems.setModel(QStandardItemModel()) | ||
|
||
def addItem(self): | ||
model = self.lstItems.model() | ||
|
||
item = QStandardItem('new item') | ||
item.setCheckable(True) | ||
item.setCheckState(Qt.Unchecked) | ||
item.setDropEnabled(False) | ||
|
||
model.appendRow(item) | ||
|
||
def removeItems(self, removeAll=False): | ||
if removeAll: | ||
self.lstItems.model().clear() | ||
else: | ||
self.lstItems.setUpdatesEnabled(False) | ||
indexes = sorted(self.lstItems.selectionModel().selectedIndexes()) | ||
for i in reversed(indexes): | ||
self.lstItems.model().removeRow(i.row()) | ||
self.lstItems.setUpdatesEnabled(True) | ||
|
||
def options(self): | ||
items = [] | ||
model = self.lstItems.model() | ||
for i in range(model.rowCount()): | ||
item = model.item(i) | ||
items.append(item.text()) | ||
|
||
return items | ||
|
||
def defaultOption(self): | ||
model = self.lstItems.model() | ||
for i in range(model.rowCount()): | ||
item = model.item(i) | ||
if item.checkState() == Qt.Checked: | ||
return i | ||
return None | ||
|
||
def allowMultiple(self): | ||
return self.chkAllowMultiple.isChecked() | ||
|
||
def setOptions(self, options): | ||
model = self.lstItems.model() | ||
for i in options: | ||
item = QStandardItem() | ||
item.setCheckable(True) | ||
item.setCheckState(Qt.Unchecked) | ||
item.setDropEnabled(False) | ||
|
||
model.appendRow(item) | ||
|
||
def setDefault(self, index): | ||
model = self.lstItems.model() | ||
item = model.item(index, 0) | ||
if item: | ||
item.setCheckState(Qt.Checked) | ||
|
||
def setAllowMultiple(self): | ||
self.chkAllowMultiple.setChecked(True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<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 row="1" column="1"> | ||
<widget class="QToolButton" name="btnRemove"> | ||
<property name="toolTip"> | ||
<string>Remove item</string> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1"> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>190</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QToolButton" name="btnAdd"> | ||
<property name="toolTip"> | ||
<string>Add item</string> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QToolButton" name="btnClear"> | ||
<property name="toolTip"> | ||
<string>Clear all</string> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0" rowspan="4"> | ||
<widget class="QListView" name="lstItems"> | ||
<property name="dragDropMode"> | ||
<enum>QAbstractItemView::InternalMove</enum> | ||
</property> | ||
<property name="alternatingRowColors"> | ||
<bool>true</bool> | ||
</property> | ||
<property name="selectionMode"> | ||
<enum>QAbstractItemView::ExtendedSelection</enum> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="4" column="0" colspan="2"> | ||
<widget class="QCheckBox" name="chkAllowMultiple"> | ||
<property name="text"> | ||
<string>Allow multiple selection</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |