Some Outline class cleanup and restructuring
This commit is contained in:
+30
-34
@@ -13,14 +13,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from os import path
|
|
||||||
from time import time
|
from time import time
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QByteArray
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QWidget, QVBoxLayout, QTreeWidget, QTreeWidgetItem, QMenu, QAction,
|
QTreeWidget, QTreeWidgetItem, QMenu, QAction, QAbstractItemView
|
||||||
QAbstractItemView
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from nw.constants import nwKeyWords, nwLabels, nwOutline
|
from nw.constants import nwKeyWords, nwLabels, nwOutline
|
||||||
@@ -157,17 +154,9 @@ class GuiProjectOutline(QTreeWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _headerRightClick(self, clickPos):
|
def _headerRightClick(self, clickPos):
|
||||||
"""Show the header column menu, and check afterwards if a
|
"""Show the header column menu.
|
||||||
column's visibility was changed.
|
|
||||||
"""
|
"""
|
||||||
self.headerMenu.exec_(self.mapToGlobal(clickPos))
|
self.headerMenu.exec_(self.mapToGlobal(clickPos))
|
||||||
|
|
||||||
hItem = self.headerMenu.toggledItem
|
|
||||||
if hItem is not None:
|
|
||||||
self.setColumnHidden(self.colIndex[hItem], not self.headerMenu.toggleState)
|
|
||||||
self.headerMenu.toggledItem = None
|
|
||||||
self.headerMenu.toggleState = None
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _columnMoved(self, logIdx, oldVisualIdx, newVisualIdx):
|
def _columnMoved(self, logIdx, oldVisualIdx, newVisualIdx):
|
||||||
@@ -177,6 +166,15 @@ class GuiProjectOutline(QTreeWidget):
|
|||||||
self.treeOrder.insert(newVisualIdx, self.treeOrder.pop(oldVisualIdx))
|
self.treeOrder.insert(newVisualIdx, self.treeOrder.pop(oldVisualIdx))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _menuColumnToggled(self, isChecked, theItem):
|
||||||
|
"""Receive the changes to column visibility forwarded by the
|
||||||
|
header context menu.
|
||||||
|
"""
|
||||||
|
logger.verbose("User toggled Outline column '%s'" % theItem.name)
|
||||||
|
if theItem in self.colIndex:
|
||||||
|
self.setColumnHidden(self.colIndex[theItem], not isChecked)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
@@ -187,7 +185,8 @@ class GuiProjectOutline(QTreeWidget):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Load whatever we saved last time, regardless of wether it
|
# Load whatever we saved last time, regardless of wether it
|
||||||
# contains the correct names or number of columns.
|
# contains the correct names or number of columns. The names
|
||||||
|
# must be valid though.
|
||||||
tempOrder = self.optState.getValue("GuiProjectOutline", "headerOrder", [])
|
tempOrder = self.optState.getValue("GuiProjectOutline", "headerOrder", [])
|
||||||
treeOrder = []
|
treeOrder = []
|
||||||
for hName in tempOrder:
|
for hName in tempOrder:
|
||||||
@@ -196,8 +195,7 @@ class GuiProjectOutline(QTreeWidget):
|
|||||||
except:
|
except:
|
||||||
logger.warning("Ignored unknown outline column '%s'" % str(hName))
|
logger.warning("Ignored unknown outline column '%s'" % str(hName))
|
||||||
|
|
||||||
# Add columns that were not in tempOrder to treeOrder, but in
|
# Add columns that was not in the file to the treeOrder array.
|
||||||
# the default column order.
|
|
||||||
for hItem in nwOutline:
|
for hItem in nwOutline:
|
||||||
if hItem not in treeOrder:
|
if hItem not in treeOrder:
|
||||||
treeOrder.append(hItem)
|
treeOrder.append(hItem)
|
||||||
@@ -210,8 +208,8 @@ class GuiProjectOutline(QTreeWidget):
|
|||||||
logger.error("Failed to extract outline column order from previous session")
|
logger.error("Failed to extract outline column order from previous session")
|
||||||
logger.error("Column count doesn't match %d != %d" % (len(treeOrder), self.treeNCols))
|
logger.error("Column count doesn't match %d != %d" % (len(treeOrder), self.treeNCols))
|
||||||
|
|
||||||
# We load the column widths and hidden state we find in the
|
# We load whatever column widths and hidden states we find in
|
||||||
# file, and leave the rest in their default state.
|
# the file, and leave the rest in their default state.
|
||||||
tmpWidth = self.optState.getValue("GuiProjectOutline", "columnWidth", {})
|
tmpWidth = self.optState.getValue("GuiProjectOutline", "columnWidth", {})
|
||||||
for hName in tmpWidth:
|
for hName in tmpWidth:
|
||||||
try:
|
try:
|
||||||
@@ -386,6 +384,9 @@ class GuiOutlineHeaderMenu(QMenu):
|
|||||||
def __init__(self, theParent):
|
def __init__(self, theParent):
|
||||||
QMenu.__init__(self, theParent)
|
QMenu.__init__(self, theParent)
|
||||||
|
|
||||||
|
self.theParent = theParent
|
||||||
|
self.acceptToggle = True
|
||||||
|
|
||||||
mnuHead = QAction("Select Columns", self)
|
mnuHead = QAction("Select Columns", self)
|
||||||
self.addAction(mnuHead)
|
self.addAction(mnuHead)
|
||||||
self.addSeparator()
|
self.addSeparator()
|
||||||
@@ -401,38 +402,33 @@ class GuiOutlineHeaderMenu(QMenu):
|
|||||||
)
|
)
|
||||||
self.addAction(self.actionMap[hItem])
|
self.addAction(self.actionMap[hItem])
|
||||||
|
|
||||||
self.ignoreToggle = False
|
|
||||||
self.toggledItem = None
|
|
||||||
self.toggleState = None
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setHiddenState(self, hiddenState):
|
def setHiddenState(self, hiddenState):
|
||||||
"""Overwrite the checked state of the columns as the inverse of
|
"""Overwrite the checked state of the columns as the inverse of
|
||||||
the hidden state. Skip the TITLE column as it cannot be hidden.
|
the hidden state. Skip the TITLE column as it cannot be hidden.
|
||||||
"""
|
"""
|
||||||
self.ignoreToggle = True
|
self.acceptToggle = False
|
||||||
|
|
||||||
for hItem in nwOutline:
|
for hItem in nwOutline:
|
||||||
if hItem == nwOutline.TITLE or hItem not in hiddenState:
|
if hItem == nwOutline.TITLE or hItem not in hiddenState:
|
||||||
continue
|
continue
|
||||||
self.actionMap[hItem].setChecked(not hiddenState[hItem])
|
self.actionMap[hItem].setChecked(not hiddenState[hItem])
|
||||||
|
|
||||||
self.ignoreToggle = False
|
self.acceptToggle = True
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Slots
|
||||||
|
##
|
||||||
|
|
||||||
def _columnToggled(self, isChecked, theItem):
|
def _columnToggled(self, isChecked, theItem):
|
||||||
"""The user has toggled the visibility of a column. Record the
|
"""The user has toggled the visibility of a column. Forward the
|
||||||
change, but do nothing more.
|
event to the parent class only if we're accepting changes.
|
||||||
"""
|
"""
|
||||||
if self.ignoreToggle:
|
if self.acceptToggle:
|
||||||
return
|
self.theParent._menuColumnToggled(isChecked, theItem)
|
||||||
|
|
||||||
logger.verbose("User toggled Outline column '%s'" % theItem.name)
|
|
||||||
self.toggledItem = theItem
|
|
||||||
self.toggleState = isChecked
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiOutlineHeaderMenu
|
# END Class GuiOutlineHeaderMenu
|
||||||
|
|||||||
Reference in New Issue
Block a user