From 83057ae3bec7a4db6056e6376f2b83309857a27a Mon Sep 17 00:00:00 2001
From: Paul S
Date: Sun, 27 Jun 2021 13:31:08 +0200
Subject: [PATCH] =?UTF-8?q?Tabelle=20"Stuff":=20Zeilen=20k=C3=B6pieren,=20?=
=?UTF-8?q?l=C3=B6schen=20und=20einf=C3=BCgen?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
changelog.md | 7 +++-
src/main.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++----
src/main.ui | 5 ++-
4 files changed, 106 insertions(+), 10 deletions(-)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7bbe72c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+env2
diff --git a/changelog.md b/changelog.md
index b1a2513..ec07159 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,8 +1,13 @@
# Changelog GarageCalc1
+## [0.2] - 2021-06-27
+### Added
+- Möglichkeit Zeilen zu kopieren und einzufügen (sowohl Kontextmenü auf Zeilenüberschrift als auch Tastenkombination Strg+C/Strg+V)
+- Möglichkeiot Zeilen zu entfernen (sowohl Kontextmenü auf Zeilenüberschrift als auch Entfernen-Taste)
+
## [0.1] - 2021-06-27
### Added
-- first version
+- Erste Version
# Changelog GarageCalc1
diff --git a/src/main.py b/src/main.py
index 1c0c772..06296d6 100644
--- a/src/main.py
+++ b/src/main.py
@@ -14,7 +14,7 @@ import csv
# Third party imports
from PySide2.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QStatusBar, QAction, QFileDialog, \
- QAbstractItemView, QMenu, QMessageBox
+ QAbstractItemView, QMenu, QMessageBox, QInputDialog
from PySide2.QtGui import QIcon
from PySide2.QtCore import QFile, QSize, Qt
from PySide2.QtUiTools import QUiLoader
@@ -26,7 +26,7 @@ from utils import show_about, resource_path
UI_FILE = "main.ui"
APP_NAME = "Garagenraum-Rechner"
APP_DISPNAME = "GarageCalc"
-APP_VERSION = "v0.1"
+APP_VERSION = "v0.2"
APP_AUTHOR = "Paul Salajean"
APP_DESCR = "Berechnet zur Verfügung stehenden Garagenraum"
APP_COPYRIGHT = "(c) Paul Salajean 2021"
@@ -68,6 +68,7 @@ class MyMainWindow(QMainWindow):
self.ui.efWeight.setText(str("0"))
self.is_modified = False
self.opened_file = None
+ self.remembered_row = None
def load_ui(self):
loader = QUiLoader()
@@ -155,19 +156,105 @@ class MyMainWindow(QMainWindow):
tblGarage.itemChanged.connect(self.on_garage_changed)
tblStuff.itemChanged.connect(self.on_stuff_changed)
+ def keyPressEvent(self, event):
+ tblStuff = self.ui.tableStuff
+
+ modifiers = QApplication.keyboardModifiers()
+
+ key = event.key()
+
+ if modifiers == Qt.ControlModifier:
+ # get selected row
+ sel_rows_idx = tblStuff.selectionModel().selectedRows()
+ row = sel_rows_idx[0].row() # there is onle on row because of singleton selection mode
+
+ if key == Qt.Key_C:
+ self.remembered_row = row
+
+ elif key == Qt.Key_V:
+ self.row_insert(tblStuff, self.remembered_row, row)
+
+ if key == Qt.Key_Delete:
+ self.row_remove(tblStuff)
+
+ def row_remove(self, table):
+ # get selected row
+ sel_rows_idx = table.selectionModel().selectedRows()
+ row = sel_rows_idx[0].row() # there is onle on row because of singleton selection mode
+
+ stuff = None
+ item_stuff = table.item(row, COL_STUFF)
+ if item_stuff:
+ stuff = item_stuff.text()
+
+ if stuff:
+ msg = f"Zeile Nr. {row+1} '{stuff}' entfernen?"
+ else:
+ msg = f"Zeile Nr. {row+1} entfernen?"
+ reply = QMessageBox.question(self, "Zeile entfernen", msg, \
+ QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
+ if reply == QMessageBox.Yes:
+ table.removeRow(row)
+ self.calc_voluminae()
+
+ def row_insert(self, table, source_row, target_row):
+ # check if empty
+ item_stuff = table.item(target_row, COL_STUFF)
+ item_length = table.item(target_row, COL_LENGTH)
+ item_width = table.item(target_row, COL_WIDTH)
+ item_height = table.item(target_row, COL_HEIGHT)
+ item_weight = table.item(target_row, COL_WEIGHT)
+
+ if item_stuff or item_length or item_width or item_height or item_weight:
+ msg = "Es sind bereits Werte in dieser Zeile vorhanden. Trotzdem fortfahren?"
+ reply = QMessageBox.question(self, "Zeile einfügen", msg, \
+ QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
+ if reply == QMessageBox.No:
+ return False
+
+ item_stuff = table.item(source_row, COL_STUFF)
+ item_length = table.item(source_row, COL_LENGTH)
+ item_width = table.item(source_row, COL_WIDTH)
+ item_height = table.item(source_row, COL_HEIGHT)
+ item_weight = table.item(source_row, COL_WEIGHT)
+
+ if item_stuff:
+ table.setItem(target_row, COL_STUFF, QTableWidgetItem(item_stuff.text()))
+
+ if item_length:
+ table.setItem(target_row, COL_LENGTH, QTableWidgetItem(item_length.text()))
+
+ if item_width:
+ table.setItem(target_row, COL_WIDTH, QTableWidgetItem(item_width.text()))
+
+ if item_height:
+ table.setItem(target_row, COL_HEIGHT, QTableWidgetItem(item_height.text()))
+
+ if item_weight:
+ table.setItem(target_row, COL_WEIGHT, QTableWidgetItem(item_weight.text()))
+
def show_rowheader_context_menu(self, position):
tblStuff = self.ui.tableStuff
row = self.headers.logicalIndexAt(position)
menu = QMenu()
- remove_row = menu.addAction("Zeile entfernen")
- insert_row = menu.addAction("Zeile einfügen")
+ row_add = menu.addAction("Zeile hinzufügen")
+ row_remove = menu.addAction("Zeile entfernen (Entf.-Taste)")
+ menu.addSeparator()
+ row_copy = menu.addAction("Zeile kopieren (Strg+C)")
+ row_insert = menu.addAction("Zeile einfügen (Strg+V)")
ac = menu.exec_(tblStuff.mapToGlobal(position))
- if ac == remove_row:
- tblStuff.removeRow(row)
- self.calc_voluminae()
- elif ac == insert_row:
+ if ac == row_remove:
+ # tblStuff.removeRow(row)
+ # self.calc_voluminae()
+ self.row_remove(tblStuff)
+
+ elif ac == row_add:
tblStuff.insertRow(row)
+ elif ac == row_copy:
+ self.remembered_row = row
+ elif ac == row_insert:
+ self.row_insert(tblStuff, self.remembered_row, row)
def init_ui(self):
tblGarage = self.ui.tableGarage
diff --git a/src/main.ui b/src/main.ui
index c8bdd36..c799198 100644
--- a/src/main.ui
+++ b/src/main.ui
@@ -225,7 +225,10 @@
true
- QAbstractItemView::NoSelection
+ QAbstractItemView::SingleSelection
+
+
+ QAbstractItemView::SelectRows