mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-11 07:18:15 +00:00
ExcludeTypes: Add combo box for filtering lists by attribute membership.
This by itself does not include/exclude types. Closes #125
This commit is contained in:
parent
f5c2ff345a
commit
0ca66d2302
@ -6,12 +6,12 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>485</width>
|
<width>619</width>
|
||||||
<height>340</height>
|
<height>340</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Exclude Types From Analysis</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
@ -118,7 +118,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="2">
|
<item row="6" column="2">
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@ -128,6 +128,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QComboBox" name="attr">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>150</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Filter types by attribute:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="1" column="0" rowspan="4">
|
<item row="1" column="0" rowspan="4">
|
||||||
<widget class="QListView" name="included_types">
|
<widget class="QListView" name="included_types">
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
|
@ -41,25 +41,33 @@ class ExcludeTypes(SEToolsWidget, QDialog):
|
|||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
self.load_ui("exclude_types.ui")
|
self.load_ui("exclude_types.ui")
|
||||||
self.exclude_a_type.clicked.connect(self.exclude_clicked)
|
|
||||||
self.include_a_type.clicked.connect(self.include_clicked)
|
# populate the attribute combo box:
|
||||||
|
self.attr_model = SEToolsListModel(self)
|
||||||
|
self.attr_model.item_list = [""] + sorted(self.policy.typeattributes())
|
||||||
|
self.attr.setModel(self.attr_model)
|
||||||
|
|
||||||
# populate the models:
|
# populate the models:
|
||||||
self.included_model = SEToolsListModel(self)
|
self.included_model = SEToolsListModel(self)
|
||||||
self.included_model.item_list = [t for t in self.policy.types()
|
self.included_model.item_list = [t for t in self.policy.types()
|
||||||
if t not in self.initial_excluded_list]
|
if t not in self.initial_excluded_list]
|
||||||
self.included_sort = QSortFilterProxyModel(self)
|
self.included_sort = FilterByAttributeProxy(self)
|
||||||
self.included_sort.setSourceModel(self.included_model)
|
self.included_sort.setSourceModel(self.included_model)
|
||||||
self.included_sort.sort(0, Qt.AscendingOrder)
|
self.included_sort.sort(0, Qt.AscendingOrder)
|
||||||
self.included_types.setModel(self.included_sort)
|
self.included_types.setModel(self.included_sort)
|
||||||
|
|
||||||
self.excluded_model = SEToolsListModel(self)
|
self.excluded_model = SEToolsListModel(self)
|
||||||
self.excluded_model.item_list = self.initial_excluded_list
|
self.excluded_model.item_list = self.initial_excluded_list
|
||||||
self.excluded_sort = QSortFilterProxyModel(self)
|
self.excluded_sort = FilterByAttributeProxy(self)
|
||||||
self.excluded_sort.setSourceModel(self.excluded_model)
|
self.excluded_sort.setSourceModel(self.excluded_model)
|
||||||
self.excluded_sort.sort(0, Qt.AscendingOrder)
|
self.excluded_sort.sort(0, Qt.AscendingOrder)
|
||||||
self.excluded_types.setModel(self.excluded_sort)
|
self.excluded_types.setModel(self.excluded_sort)
|
||||||
|
|
||||||
|
# connect signals
|
||||||
|
self.exclude_a_type.clicked.connect(self.exclude_clicked)
|
||||||
|
self.include_a_type.clicked.connect(self.include_clicked)
|
||||||
|
self.attr.currentIndexChanged.connect(self.set_attr_filter)
|
||||||
|
|
||||||
def include_clicked(self):
|
def include_clicked(self):
|
||||||
selected_types = []
|
selected_types = []
|
||||||
for index in self.excluded_types.selectionModel().selectedIndexes():
|
for index in self.excluded_types.selectionModel().selectedIndexes():
|
||||||
@ -86,8 +94,41 @@ class ExcludeTypes(SEToolsWidget, QDialog):
|
|||||||
for item in selected_types:
|
for item in selected_types:
|
||||||
self.included_model.remove(item)
|
self.included_model.remove(item)
|
||||||
|
|
||||||
|
def set_attr_filter(self, row):
|
||||||
|
index = self.attr_model.index(row)
|
||||||
|
attr = self.attr_model.data(index, Qt.UserRole)
|
||||||
|
self.log.debug("Attribute set to {0!r}".format(attr))
|
||||||
|
self.included_sort.attr = attr
|
||||||
|
self.excluded_sort.attr = attr
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.log.debug("Chosen for exclusion: {0!r}".format(self.excluded_model.item_list))
|
self.log.debug("Chosen for exclusion: {0!r}".format(self.excluded_model.item_list))
|
||||||
|
|
||||||
self.parent.query.exclude = self.excluded_model.item_list
|
self.parent.query.exclude = self.excluded_model.item_list
|
||||||
super(ExcludeTypes, self).accept()
|
super(ExcludeTypes, self).accept()
|
||||||
|
|
||||||
|
|
||||||
|
class FilterByAttributeProxy(QSortFilterProxyModel):
|
||||||
|
|
||||||
|
"""Filter a list of types by attribute membership."""
|
||||||
|
|
||||||
|
_attr = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def attr(self):
|
||||||
|
return self._attr
|
||||||
|
|
||||||
|
@attr.setter
|
||||||
|
def attr(self, value):
|
||||||
|
self._attr = value
|
||||||
|
self.invalidateFilter()
|
||||||
|
|
||||||
|
def filterAcceptsRow(self, row, parent):
|
||||||
|
if self.attr:
|
||||||
|
source = self.sourceModel()
|
||||||
|
index = source.index(row)
|
||||||
|
item = source.data(index, Qt.UserRole)
|
||||||
|
if item not in self.attr:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user