Draft: Turned autogroup button into layers selector (added pref option to restore old groups-based system)

This commit is contained in:
Yorik van Havre
2019-06-30 01:00:50 -03:00
parent ee446ee441
commit f717d540c8
5 changed files with 160 additions and 203 deletions

View File

@@ -435,7 +435,10 @@ class DraftToolBar:
if hide:
button.hide()
if icon:
button.setIcon(QtGui.QIcon.fromTheme(icon, QtGui.QIcon(':/icons/'+icon+'.svg')))
if icon.endswith(".svg"):
button.setIcon(QtGui.QIcon(icon))
else:
button.setIcon(QtGui.QIcon.fromTheme(icon, QtGui.QIcon(':/icons/'+icon+'.svg')))
#button.setIconSize(QtCore.QSize(isize, isize))
if checkable:
button.setCheckable(True)
@@ -772,9 +775,10 @@ class DraftToolBar:
self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(bsize * 2,bsize))
self.widthButton.setSuffix("px")
self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(bsize * 4,bsize))
self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True)
self.autoGroupButton = self._pushbutton("autoGroup",self.bottomtray,icon="Draft_AutoGroup_off",hide=False,width=120)
self.autoGroupButton = self._pushbutton("autoGroup",self.bottomtray,icon=":/icons/button_invalid.svg",hide=False,width=120)
self.autoGroupButton.setText("None")
self.autoGroupButton.setFlat(True)
self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True)
QtCore.QObject.connect(self.wplabel,QtCore.SIGNAL("pressed()"),self.selectplane)
QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol)
@@ -2022,15 +2026,21 @@ class DraftToolBar:
def selectplane(self):
FreeCADGui.runCommand("Draft_SelectPlane")
def popupMenu(self,mlist):
def popupMenu(self,llist,ilist=None):
"pops up a menu filled with the given list"
self.groupmenu = QtGui.QMenu()
for i in mlist:
self.groupmenu.addAction(i)
for i,l in enumerate(llist):
if ilist:
self.groupmenu.addAction(ilist[i],l)
else:
self.groupmenu.addAction(l)
pos = FreeCADGui.getMainWindow().cursor().pos()
self.groupmenu.popup(pos)
QtCore.QObject.connect(self.groupmenu,QtCore.SIGNAL("triggered(QAction *)"),self.popupTriggered)
def getIcon(self,iconpath):
return QtGui.QIcon(iconpath)
def popupTriggered(self,action):
self.sourceCmd.proceed(str(action.text()))
@@ -2093,7 +2103,7 @@ class DraftToolBar:
self.autogroup = None
self.autoGroupButton.setText("None")
self.autoGroupButton.setIcon(QtGui.QIcon.fromTheme('Draft_AutoGroup_off',
QtGui.QIcon(':/icons/Draft_AutoGroup_off.svg')))
QtGui.QIcon(':/icons/button_invalid.svg')))
self.autoGroupButton.setToolTip(translate("draft", "Autogroup off"))
self.autoGroupButton.setDown(False)
else:
@@ -2101,15 +2111,14 @@ class DraftToolBar:
if obj:
self.autogroup = value
self.autoGroupButton.setText(obj.Label)
self.autoGroupButton.setIcon(QtGui.QIcon.fromTheme('Draft_AutoGroup_on',
QtGui.QIcon(':/icons/Draft_AutoGroup_on.svg')))
self.autoGroupButton.setIcon(obj.ViewObject.Icon)
self.autoGroupButton.setToolTip(translate("draft", "Autogroup: ")+obj.Label)
self.autoGroupButton.setDown(False)
else:
self.autogroup = None
self.autoGroupButton.setText("None")
self.autoGroupButton.setIcon(QtGui.QIcon.fromTheme('Draft_AutoGroup_off',
QtGui.QIcon(':/icons/Draft_AutoGroup_off.svg')))
QtGui.QIcon(':/icons/button_invalid.svg')))
self.autoGroupButton.setToolTip(translate("draft", "Autogroup off"))
self.autoGroupButton.setDown(False)

View File

@@ -277,6 +277,20 @@ class ViewProviderLayer:
parent.Group = g
FreeCAD.ActiveDocument.recompute()
def setupContextMenu(self,vobj,menu):
from PySide import QtCore,QtGui
action1 = QtGui.QAction(QtGui.QIcon(":/icons/button_right.svg"),translate("draft","Activate this layer"),menu)
action1.triggered.connect(self.activate)
menu.addAction(action1)
def activate(self):
if hasattr(self,"Object"):
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(self.Object)
FreeCADGui.runCommand("Draft_AutoGroup")
class LayerContainer:
@@ -289,7 +303,9 @@ class LayerContainer:
def execute(self,obj):
return
g = obj.Group
g.sort(key=lambda o: o.Label)
obj.Group = g
def __getstate__(self):

View File

@@ -5303,20 +5303,26 @@ class SetAutoGroup():
self.ui = FreeCADGui.draftToolBar
s = FreeCADGui.Selection.getSelection()
if len(s) == 1:
if s[0].isDerivedFrom("App::DocumentObjectGroup") or (Draft.getType(s[0]) in ["Site","Building","Floor"]):
if (Draft.getType(s[0]) == "Layer") or \
( FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("AutogroupAddGroups",False) and \
(s[0].isDerivedFrom("App::DocumentObjectGroup") or (Draft.getType(s[0]) in ["Site","Building","Floor","BuildingPart",]))):
self.ui.setAutoGroup(s[0].Name)
return
self.groups = ["None"]
gn = Draft.getGroupNames()
gn = [o.Name for o in FreeCAD.ActiveDocument.Objects if Draft.getType(o) == "Layer"]
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("AutogroupAddGroups",False):
gn.extend(Draft.getGroupNames())
if gn:
self.groups.extend(gn)
self.labels = ["None"]
self.icons = [self.ui.getIcon(":/icons/button_invalid.svg")]
for g in gn:
o = FreeCAD.ActiveDocument.getObject(g)
if o:
self.labels.append(o.Label)
self.icons.append(o.ViewObject.Icon)
self.ui.sourceCmd = self
self.ui.popupMenu(self.labels)
self.ui.popupMenu(self.labels,self.icons)
def proceed(self,labelname):
self.ui.sourceCmd = None

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>486</width>
<height>758</height>
<height>781</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,16 +17,7 @@
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>9</number>
</property>
<item>
@@ -373,6 +364,25 @@ Values with differences below this value will be treated as same. This value wil
</item>
</layout>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_3">
<property name="toolTip">
<string>If this option is checked, the layers drop-down list will also show groups, allowing you to automatically add objects to groups too.</string>
</property>
<property name="text">
<string>Show groups in layers list drop-down button</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>AutogroupAddGroups</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -442,7 +452,7 @@ Values with differences below this value will be treated as same. This value wil
<property name="toolTip">
<string>This is the default color for objects being drawn while in construction mode.</string>
</property>
<property name="color" stdset="0">
<property name="color">
<color>
<red>44</red>
<green>125</green>
@@ -505,14 +515,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRelative</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRelative</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -555,14 +565,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutContinue</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutContinue</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -605,14 +615,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutClose</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutClose</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -657,14 +667,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutCopy</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutCopy</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -705,14 +715,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSubelementMode</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSubelementMode</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -753,14 +763,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutFill</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutFill</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -805,14 +815,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutExit</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutExit</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -853,14 +863,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSelectEdge</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSelectEdge</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -901,14 +911,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutAddHold</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutAddHold</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -953,14 +963,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutLength</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutLength</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1001,14 +1011,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutWipe</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutWipe</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1049,14 +1059,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSetWP</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSetWP</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1101,14 +1111,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutCycleSnap</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutCycleSnap</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1159,14 +1169,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSnap</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutSnap</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1207,14 +1217,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutIncreaseRadius</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutIncreaseRadius</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1255,14 +1265,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutDecreaseRadius</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutDecreaseRadius</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1307,14 +1317,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRestrictX</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRestrictX</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1355,14 +1365,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRestrictY</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>inCommandShortcutRestrictY</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1403,14 +1413,14 @@ Values with differences below this value will be treated as same. This value wil
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="prefEntry" stdset="0">
<cstring>RestrictZ</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>RestrictZ</cstring>
<property name="clearButtonEnabled" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -1439,11 +1449,21 @@ Values with differences below this value will be treated as same. This value wil
<layoutdefault spacing="6" margin="11"/>
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>Gui::ColorButton</class>
<extends>QPushButton</extends>
<header>Gui/Widgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefColorButton</class>
<extends>Gui::ColorButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
@@ -1454,26 +1474,16 @@ Values with differences below this value will be treated as same. This value wil
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::ColorButton</class>
<extends>QPushButton</extends>
<header>Gui/Widgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefColorButton</class>
<extends>Gui::ColorButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefLineEdit</class>
<extends>QLineEdit</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>532</width>
<height>484</height>
<width>531</width>
<height>552</height>
</rect>
</property>
<property name="windowTitle">
@@ -26,90 +26,6 @@
<string>Visual Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default line color</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::PrefColorButton" name="gui::prefcolorbutton">
<property name="toolTip">
<string>The default color for new objects</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>color</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Default line width</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="gui::prefspinbox">
<property name="toolTip">
<string>The default linewidth for new objects</string>
</property>
<property name="value">
<number>2</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>linewidth</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>