Skip to content

Commit

Permalink
Add first basic FilterEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeil committed Mar 19, 2022
1 parent dd416aa commit 1075249
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 1 deletion.
104 changes: 104 additions & 0 deletions res/filter_editor.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilterEditor</class>
<widget class="QDialog" name="FilterEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>129</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Discard|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_spalte">
<property name="text">
<string>Spalte</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_filter">
<property name="text">
<string>Filter</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>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combobox_column"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combobox_filteroption"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_filteroption">
<property name="text">
<string>Filteroption</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FilterEditor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FilterEditor</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
54 changes: 54 additions & 0 deletions src/filter_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from datetime import datetime
from typing import Dict

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QDialog, QLineEdit, QCheckBox, QDateEdit, QSpinBox

from src.datatypes import QuestionParameters
from src.ui_filter_editor import Ui_FilterEditor


class FilterEditor(QDialog, Ui_FilterEditor):
def __init__(self, filter_configuration: Dict[str, QuestionParameters], current_filter=None, parent=None,
window_flags=Qt.Dialog):
super(FilterEditor, self).__init__(parent, window_flags)
self.ui = Ui_FilterEditor()
self.ui.setupUi(self)
self.filter = None

if current_filter:
self.setWindowTitle("Filter bearbeiten")
else:
self.setWindowTitle("Filter erstellen")

self.filter_configuration = filter_configuration

self.ui.combobox_column.addItems(
[filterparams.table_header for filterparams in self.filter_configuration.values()])
self.update_filteroptions(self.ui.combobox_column.currentIndex())

self.ui.combobox_column.currentIndexChanged.connect(self.update_filteroptions)

def update_filteroptions(self, index):
self.ui.combobox_filteroption.clear()

current_params = list(self.filter_configuration.values())[index]
self.ui.combobox_filteroption.addItems([str(options) for options in current_params.filter_options])

if self.filter:
self.ui.gridLayout.removeWidget(self.filter)
self.filter.deleteLater()
self.filter = None

if current_params.datatype == str:
self.filter = QLineEdit()
elif current_params.datatype == bool:
self.filter = QCheckBox()
elif current_params.datatype == datetime:
self.filter = QDateEdit()
elif current_params.datatype == int:
self.filter = QSpinBox()
else:
return

self.ui.gridLayout.addWidget(self.filter, 2, 1, 1, 1)
10 changes: 9 additions & 1 deletion src/main_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from . import controller, document_builder
from .basic_config import app_version, check_for_update, display_name, is_bundled
from .datatypes import Rulegroup, create_rulegroups, create_questions_and_mchoice
from .filter_editor import FilterEditor
from .question_table import RulegroupView, RuleDataModel, RuleSortFilterProxyModel
from .regeltestcreator import RegeltestSaveDialog, RegeltestSetup
from .ui_mainwindow import Ui_MainWindow
Expand Down Expand Up @@ -187,7 +188,14 @@ def add_filter(self):
properties = {}
for i in range(first_ruletab.columnCount()):
properties.update(first_ruletab.headerData(i, Qt.Horizontal, Qt.UserRole))
print(properties)
editor = FilterEditor(properties)
return_val = editor.exec()
if return_val == QMessageBox.Discard:
print("Discarded")
elif return_val == QMessageBox.Save:
print("Saved")
else:
print("Closed")

def filter_column(self, column, keyword, mode=FilterMode.Include):
# RuleSortFilterProxyModel.add_filter(('answer_text', lambda x: 'FaD' in x))
Expand Down
72 changes: 72 additions & 0 deletions src/ui_filter_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'filter_editor.ui'
##
## Created by: Qt User Interface Compiler version 6.2.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QMetaObject, Qt)
from PySide6.QtWidgets import (QComboBox, QDialogButtonBox, QGridLayout, QLabel, QSizePolicy,
QSpacerItem)


class Ui_FilterEditor(object):
def setupUi(self, FilterEditor):
if not FilterEditor.objectName():
FilterEditor.setObjectName(u"FilterEditor")
FilterEditor.resize(400, 129)
self.gridLayout = QGridLayout(FilterEditor)
self.gridLayout.setObjectName(u"gridLayout")
self.buttonBox = QDialogButtonBox(FilterEditor)
self.buttonBox.setObjectName(u"buttonBox")
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Discard | QDialogButtonBox.Save)

self.gridLayout.addWidget(self.buttonBox, 4, 1, 1, 1)

self.label_spalte = QLabel(FilterEditor)
self.label_spalte.setObjectName(u"label_spalte")

self.gridLayout.addWidget(self.label_spalte, 0, 0, 1, 1)

self.label_filter = QLabel(FilterEditor)
self.label_filter.setObjectName(u"label_filter")

self.gridLayout.addWidget(self.label_filter, 2, 0, 1, 1)

self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

self.gridLayout.addItem(self.verticalSpacer, 3, 1, 1, 1)

self.combobox_column = QComboBox(FilterEditor)
self.combobox_column.setObjectName(u"combobox_column")

self.gridLayout.addWidget(self.combobox_column, 0, 1, 1, 1)

self.combobox_filteroption = QComboBox(FilterEditor)
self.combobox_filteroption.setObjectName(u"combobox_filteroption")

self.gridLayout.addWidget(self.combobox_filteroption, 1, 1, 1, 1)

self.label_filteroption = QLabel(FilterEditor)
self.label_filteroption.setObjectName(u"label_filteroption")

self.gridLayout.addWidget(self.label_filteroption, 1, 0, 1, 1)

self.retranslateUi(FilterEditor)
self.buttonBox.accepted.connect(FilterEditor.accept)
self.buttonBox.rejected.connect(FilterEditor.reject)

QMetaObject.connectSlotsByName(FilterEditor)

# setupUi

def retranslateUi(self, FilterEditor):
FilterEditor.setWindowTitle(QCoreApplication.translate("FilterEditor", u"Dialog", None))
self.label_spalte.setText(QCoreApplication.translate("FilterEditor", u"Spalte", None))
self.label_filter.setText(QCoreApplication.translate("FilterEditor", u"Filter", None))
self.label_filteroption.setText(QCoreApplication.translate("FilterEditor", u"Filteroption", None))
# retranslateUi

0 comments on commit 1075249

Please sign in to comment.