From 1fae92b4eeef8da308ada4b336e41876d3f39235 Mon Sep 17 00:00:00 2001 From: Simon Vetter Date: Tue, 30 Jul 2024 15:11:39 +0200 Subject: [PATCH] Add indirect edit actions to table context menus Closes #217 --- src/db/normal_table.h | 8 ++ src/db/tables_spec/ascents_table.cpp | 10 ++ src/db/tables_spec/ascents_table.h | 1 + src/db/tables_spec/countries_table.cpp | 10 ++ src/db/tables_spec/countries_table.h | 1 + src/db/tables_spec/hikers_table.cpp | 10 ++ src/db/tables_spec/hikers_table.h | 1 + src/db/tables_spec/peaks_table.cpp | 10 ++ src/db/tables_spec/peaks_table.h | 1 + src/db/tables_spec/photos_table.cpp | 10 ++ src/db/tables_spec/photos_table.h | 1 + src/db/tables_spec/ranges_table.cpp | 10 ++ src/db/tables_spec/ranges_table.h | 1 + src/db/tables_spec/regions_table.cpp | 10 ++ src/db/tables_spec/regions_table.h | 1 + src/db/tables_spec/trips_table.cpp | 10 ++ src/db/tables_spec/trips_table.h | 1 + src/main/main_window.cpp | 34 ++++- src/main/main_window.h | 1 + src/main/main_window_tab_content.cpp | 115 ++++++++++++--- src/main/main_window_tab_content.h | 17 ++- src/viewer/ascent_viewer.cpp | 6 +- translation/de.ts | 189 ++++++++++++++----------- translation/en.ts | 48 +++---- 24 files changed, 368 insertions(+), 138 deletions(-) diff --git a/src/db/normal_table.h b/src/db/normal_table.h index 7dc255b..1f82df2 100644 --- a/src/db/normal_table.h +++ b/src/db/normal_table.h @@ -83,6 +83,14 @@ class NormalTable : public Table { * @return The translated string representing absence of an item of the table's type. */ virtual QString getNoneString() const = 0; + /** + * Returns a translated prompt to edit an existing item of this table's type. + * + * Should end in ellipses ("...") to indicate that a dialog will be opened. + * + * @return The translated prompt to edit an existing item. + */ + virtual QString getEditItemString() const = 0; /** * Returns a translated message confirming that a new item of this table's type has been * created. diff --git a/src/db/tables_spec/ascents_table.cpp b/src/db/tables_spec/ascents_table.cpp index 2be1897..5a2fd43 100644 --- a/src/db/tables_spec/ascents_table.cpp +++ b/src/db/tables_spec/ascents_table.cpp @@ -214,6 +214,16 @@ QString AscentsTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing ascent. + * + * @return The translated prompt to edit an existing ascent. + */ +QString AscentsTable::getEditItemString() const +{ + return tr("Edit ascent..."); +} + /** * Returns a translated message confirming that a new ascent has been created. * diff --git a/src/db/tables_spec/ascents_table.h b/src/db/tables_spec/ascents_table.h index 88c9519..dcd22fb 100644 --- a/src/db/tables_spec/ascents_table.h +++ b/src/db/tables_spec/ascents_table.h @@ -77,6 +77,7 @@ class AscentsTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/countries_table.cpp b/src/db/tables_spec/countries_table.cpp index a2abd62..ae423f5 100644 --- a/src/db/tables_spec/countries_table.cpp +++ b/src/db/tables_spec/countries_table.cpp @@ -159,6 +159,16 @@ QString CountriesTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing country. + * + * @return The translated prompt to edit an existing country. + */ +QString CountriesTable::getEditItemString() const +{ + return tr("Edit country..."); +} + /** * Returns a translated message confirming that a new country has been created. * diff --git a/src/db/tables_spec/countries_table.h b/src/db/tables_spec/countries_table.h index 46b18ac..7df1d0d 100644 --- a/src/db/tables_spec/countries_table.h +++ b/src/db/tables_spec/countries_table.h @@ -55,6 +55,7 @@ class CountriesTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/hikers_table.cpp b/src/db/tables_spec/hikers_table.cpp index da15357..88c60f9 100644 --- a/src/db/tables_spec/hikers_table.cpp +++ b/src/db/tables_spec/hikers_table.cpp @@ -159,6 +159,16 @@ QString HikersTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing hiker. + * + * @return The translated prompt to edit an existing hiker. + */ +QString HikersTable::getEditItemString() const +{ + return tr("Edit hiker..."); +} + /** * Returns a translated message confirming that a new hiker has been created. * diff --git a/src/db/tables_spec/hikers_table.h b/src/db/tables_spec/hikers_table.h index 1962497..15c256e 100644 --- a/src/db/tables_spec/hikers_table.h +++ b/src/db/tables_spec/hikers_table.h @@ -55,6 +55,7 @@ class HikersTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/peaks_table.cpp b/src/db/tables_spec/peaks_table.cpp index f08fc3d..bea9539 100644 --- a/src/db/tables_spec/peaks_table.cpp +++ b/src/db/tables_spec/peaks_table.cpp @@ -178,6 +178,16 @@ QString PeaksTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing peak. + * + * @return The translated prompt to edit an existing peak. + */ +QString PeaksTable::getEditItemString() const +{ + return tr("Edit peak..."); +} + /** * Returns a translated message confirming that a new peak has been created. * diff --git a/src/db/tables_spec/peaks_table.h b/src/db/tables_spec/peaks_table.h index e930cf0..bb90b0b 100644 --- a/src/db/tables_spec/peaks_table.h +++ b/src/db/tables_spec/peaks_table.h @@ -67,6 +67,7 @@ class PeaksTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/photos_table.cpp b/src/db/tables_spec/photos_table.cpp index 3f84602..33819ec 100644 --- a/src/db/tables_spec/photos_table.cpp +++ b/src/db/tables_spec/photos_table.cpp @@ -260,6 +260,16 @@ QString PhotosTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing photo. + * + * @return The translated prompt to edit an existing photo. + */ +QString PhotosTable::getEditItemString() const +{ + return tr("Edit photo..."); +} + /** * Returns a translated message confirming that a new photo has been created. * diff --git a/src/db/tables_spec/photos_table.h b/src/db/tables_spec/photos_table.h index b5cf203..05900bf 100644 --- a/src/db/tables_spec/photos_table.h +++ b/src/db/tables_spec/photos_table.h @@ -69,6 +69,7 @@ class PhotosTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/ranges_table.cpp b/src/db/tables_spec/ranges_table.cpp index d1879c3..d8e2eee 100644 --- a/src/db/tables_spec/ranges_table.cpp +++ b/src/db/tables_spec/ranges_table.cpp @@ -164,6 +164,16 @@ QString RangesTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing mountain range. + * + * @return The translated prompt to edit an existing mountain range. + */ +QString RangesTable::getEditItemString() const +{ + return tr("Edit mountain range..."); +} + /** * Returns a translated message confirming that a new mountain range has been created. * diff --git a/src/db/tables_spec/ranges_table.h b/src/db/tables_spec/ranges_table.h index 87391d3..2c172e1 100644 --- a/src/db/tables_spec/ranges_table.h +++ b/src/db/tables_spec/ranges_table.h @@ -57,6 +57,7 @@ class RangesTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/regions_table.cpp b/src/db/tables_spec/regions_table.cpp index 211a0ba..bd80231 100644 --- a/src/db/tables_spec/regions_table.cpp +++ b/src/db/tables_spec/regions_table.cpp @@ -167,6 +167,16 @@ QString RegionsTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing region. + * + * @return The translated prompt to edit an existing region. + */ +QString RegionsTable::getEditItemString() const +{ + return tr("Edit region..."); +} + /** * Returns a translated message confirming that a new region has been created. * diff --git a/src/db/tables_spec/regions_table.h b/src/db/tables_spec/regions_table.h index bd66984..0dd40a6 100644 --- a/src/db/tables_spec/regions_table.h +++ b/src/db/tables_spec/regions_table.h @@ -57,6 +57,7 @@ class RegionsTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/db/tables_spec/trips_table.cpp b/src/db/tables_spec/trips_table.cpp index 945f7f6..f9fe2af 100644 --- a/src/db/tables_spec/trips_table.cpp +++ b/src/db/tables_spec/trips_table.cpp @@ -174,6 +174,16 @@ QString TripsTable::getNoneString() const return tr("None"); } +/** + * Returns a translated prompt to edit an existing trip. + * + * @return The translated prompt to edit an existing trip. + */ +QString TripsTable::getEditItemString() const +{ + return tr("Edit trip..."); +} + /** * Returns a translated message confirming that a new trip has been created. * diff --git a/src/db/tables_spec/trips_table.h b/src/db/tables_spec/trips_table.h index 9a63a67..8296098 100644 --- a/src/db/tables_spec/trips_table.h +++ b/src/db/tables_spec/trips_table.h @@ -61,6 +61,7 @@ class TripsTable : public NormalTable { virtual QString getItemNameSingular() const override; virtual QString getNoneString() const override; + virtual QString getEditItemString() const override; virtual QString getCreationConfirmMessage() const override; virtual QString getEditConfirmMessage(int numEdited) const override; virtual QString getDeleteConfirmMessage(int numDeleted) const override; diff --git a/src/main/main_window.cpp b/src/main/main_window.cpp index 5e8ac18..1393d00 100644 --- a/src/main/main_window.cpp +++ b/src/main/main_window.cpp @@ -228,7 +228,7 @@ void MainWindow::setupTableTabs() const bool isViewable = mapper->type == ItemTypeAscent; const bool isDuplicable = mapper->type == ItemTypeAscent || mapper->type == ItemTypePeak; - mapper->tab.init(this, mapper, isViewable, isDuplicable); + mapper->tab.init(this, typesHandler, mapper, db, isViewable, isDuplicable); } } @@ -589,8 +589,8 @@ void MainWindow::editSelectedItems() if (selectedBufferRows.isEmpty()) return; const int numSelectedRows = selectedBufferRows.size(); - auto callWhenDone = [=, &activeMapper](bool changedMade) { - if (!changedMade) return; + auto callWhenDone = [=, &activeMapper](bool changesMade) { + if (!changesMade) return; setStatusLine(activeMapper.baseTable.getEditConfirmMessage(numSelectedRows)); performUpdatesAfterUserAction(activeMapper, false); }; @@ -602,6 +602,34 @@ void MainWindow::editSelectedItems() } } +/** + * If a single item is selected in the active table, opens a dialog for editing the item of the type + * specified via caller data that the selected item references directly (forward only). + */ +void MainWindow::editSelectedItemReferenced() +{ + const ItemTypeMapper& activeMapper = getActiveMapper(); + const QSet& selectedBufferRows = activeMapper.tab.getSelectedRows().first; + if (selectedBufferRows.size() != 1) return; + const BufferRowIndex selectedBufferRow = BufferRowIndex(selectedBufferRows.constBegin()->get()); + + const QAction* action = (QAction*) sender(); + assert(action); + const PALItemType otherType = PALItemType(action->data().toInt()); + const ItemTypeMapper& otherMapper = typesHandler->get(otherType); + + const Breadcrumbs crumbs = db.getBreadcrumbsFor(activeMapper.baseTable, otherMapper.baseTable); + const BufferRowIndex targetBufferRow = crumbs.evaluateAsForwardChain(selectedBufferRow); + + auto callWhenDone = [=, &activeMapper](bool changesMade) { + if (!changesMade) return; + setStatusLine(activeMapper.baseTable.getEditConfirmMessage(1)); + performUpdatesAfterUserAction(activeMapper, false); + }; + + otherMapper.openEditItemDialogAndStoreMethod(*this, *this, db, targetBufferRow, callWhenDone); +} + /** * Opens a dialog for deleting the selected items in the currently active table. * diff --git a/src/main/main_window.h b/src/main/main_window.h index 1e87fa3..a39bafc 100644 --- a/src/main/main_window.h +++ b/src/main/main_window.h @@ -93,6 +93,7 @@ class MainWindow : public QMainWindow, private Ui_MainWindow void newItem(const ItemTypeMapper& mapper); void duplicateAndEditSelectedItem(); void editSelectedItems(); + void editSelectedItemReferenced(); void deleteSelectedItems(); private: // Helpers diff --git a/src/main/main_window_tab_content.cpp b/src/main/main_window_tab_content.cpp index b69db91..8fc5bea 100644 --- a/src/main/main_window_tab_content.cpp +++ b/src/main/main_window_tab_content.cpp @@ -30,7 +30,9 @@ MainWindowTabContent::MainWindowTabContent(QWidget* parent) : QWidget(parent), mainWindow(nullptr), + typesHandler(nullptr), mapper(nullptr), + db(nullptr), compTable(nullptr), isViewable(false), isDuplicable(false), @@ -40,6 +42,7 @@ MainWindowTabContent::MainWindowTabContent(QWidget* parent) : tableContextMenu(QMenu(this)), tableContextMenuOpenAction(nullptr), tableContextMenuDuplicateAction(nullptr), + tableContextMenuEditOtherActions(QList>()), shortcuts(QList()) { setupUi(this); @@ -53,12 +56,14 @@ MainWindowTabContent::~MainWindowTabContent() -void MainWindowTabContent::init(MainWindow* mainWindow, ItemTypeMapper* mapper, bool viewable, bool duplicable) +void MainWindowTabContent::init(MainWindow* mainWindow, const ItemTypesHandler* typesHandler, ItemTypeMapper* mapper, Database& db, bool viewable, bool duplicable) { assert(mainWindow && mapper); this->mainWindow = mainWindow; + this->typesHandler = typesHandler; this->mapper = mapper; + this->db = &db; this->compTable = &mapper->compTable; this->isViewable = viewable; this->isDuplicable = duplicable; @@ -79,11 +84,6 @@ void MainWindowTabContent::init(MainWindow* mainWindow, ItemTypeMapper* mapper, connect(tableView->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &MainWindowTabContent::handle_rightClickOnColumnHeader); connect(tableView, &QTableView::customContextMenuRequested, this, &MainWindowTabContent::handle_rightClickInTable); - // Set table context menu icons - QIcon icon = QIcon(":/icons/" + mapper->name + ".svg"); - tableContextMenuEditAction->setIcon(icon); - if (isDuplicable) tableContextMenuDuplicateAction->setIcon(icon); - // Connect selection change listener connect(tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindowTabContent::handle_tableSelectionChanged); @@ -249,27 +249,53 @@ void MainWindowTabContent::initTableContextMenuAndShortcuts() QKeySequence duplicateKeySequence = QKeySequence::Copy; QKeySequence deleteKeySequence = QKeySequence::Delete; + const QList directlyReferencedTypes = getDirectlyReferencedTypes(); + // Context menu - QAction* openAction = tableContextMenu.addAction(tr("View..."), openKeySequence); + tableContextMenuOpenAction = tableContextMenu.addAction(tr("View..."), openKeySequence); + tableContextMenu.addSeparator(); - QAction* editAction = tableContextMenu.addAction(tr("Edit..."), editKeySequence); - QAction* duplicateAction = tableContextMenu.addAction(tr("Edit as new duplicate..."), duplicateKeySequence); + tableContextMenuEditAction = tableContextMenu.addAction(tr("Edit..."), editKeySequence); + if (isDuplicable) { + tableContextMenuDuplicateAction = tableContextMenu.addAction(tr("Edit as new duplicate..."), duplicateKeySequence); + } + + if (!directlyReferencedTypes.isEmpty()) { + tableContextMenu.addSeparator(); + // Create actions for editing directly (forward only) referenced item types + for (const PALItemType& directlyReferencedType : directlyReferencedTypes) { + const ItemTypeMapper& targetMapper = typesHandler->get(directlyReferencedType); + QAction* const editOtherAction = tableContextMenu.addAction(targetMapper.baseTable.getEditItemString()); + editOtherAction->setData(QVariant(directlyReferencedType)); + tableContextMenuEditOtherActions.append({&targetMapper, editOtherAction}); + } + } + tableContextMenu.addSeparator(); - QAction* deleteAction = tableContextMenu.addAction(tr("Delete"), deleteKeySequence); - // Store actions for open and duplicate (for disbling them where they're not needed) - tableContextMenuOpenAction = openAction; - tableContextMenuEditAction = editAction; - if (isDuplicable) tableContextMenuDuplicateAction = duplicateAction; - tableContextMenuDeleteAction = deleteAction; + tableContextMenuDeleteAction = tableContextMenu.addAction(tr("Delete"), deleteKeySequence); // Set icons - openAction->setIcon(QIcon(":/icons/ascent_viewer.svg")); - deleteAction->setIcon(style()->standardIcon(QStyle::SP_TrashIcon)); + const QIcon icon = QIcon(":/icons/" + mapper->name + ".svg"); + tableContextMenuEditAction->setIcon(icon); + if (isDuplicable) tableContextMenuDuplicateAction->setIcon(icon); + for (const auto& [otherMapper, editOtherAction] : tableContextMenuEditOtherActions) { + const QIcon otherIcon = QIcon(":/icons/" + otherMapper->name + ".svg"); + editOtherAction->setIcon(otherIcon); + } + tableContextMenuOpenAction->setIcon(QIcon(":/icons/ascent_viewer.svg")); + tableContextMenuDeleteAction->setIcon(style()->standardIcon(QStyle::SP_TrashIcon)); + + // Connect actions + connect(tableContextMenuOpenAction, &QAction::triggered, mainWindow, &MainWindow::viewSelectedItem); + connect(tableContextMenuEditAction, &QAction::triggered, mainWindow, &MainWindow::editSelectedItems); + if (isDuplicable) { + connect(tableContextMenuDuplicateAction, &QAction::triggered, mainWindow, &MainWindow::duplicateAndEditSelectedItem); + } + for (const auto& [_, editOtherAction] : tableContextMenuEditOtherActions) { + connect(editOtherAction, &QAction::triggered, mainWindow, &MainWindow::editSelectedItemReferenced); + } + connect(tableContextMenuDeleteAction, &QAction::triggered, mainWindow, &MainWindow::deleteSelectedItems); - connect(openAction, &QAction::triggered, mainWindow, &MainWindow::viewSelectedItem); - connect(editAction, &QAction::triggered, mainWindow, &MainWindow::editSelectedItems); - connect(duplicateAction, &QAction::triggered, mainWindow, &MainWindow::duplicateAndEditSelectedItem); - connect(deleteAction, &QAction::triggered, mainWindow, &MainWindow::deleteSelectedItems); // Keyboard shortcuts QShortcut* openShortcut = new QShortcut(openKeySequence, tableView); @@ -464,10 +490,25 @@ void MainWindowTabContent::handle_rightClickInTable(QPoint pos) QModelIndex index = tableView->indexAt(pos); if (!index.isValid()) return; - const bool singleRowSelected = tableView->selectionModel()->selectedRows().size() == 1; + const QSet selectedRows = getSelectedRows().first; + const bool singleRowSelected = selectedRows.size() == 1; + const BufferRowIndex singleSelectedRow = singleRowSelected ? BufferRowIndex(selectedRows.constBegin()->get()) : BufferRowIndex(); tableContextMenuOpenAction->setVisible(singleRowSelected && isViewable); if (isDuplicable) tableContextMenuDuplicateAction->setVisible(singleRowSelected); + // Enable or disable referenced item edit actions in table context menu + for (const auto& [otherMapper, editOtherAction] : tableContextMenuEditOtherActions) { + bool enableAction = singleRowSelected; + if (singleRowSelected) { + // Check whether reference chain is continuous here + const Breadcrumbs crumbs = db->getBreadcrumbsFor(mapper->baseTable, otherMapper->baseTable); + const BufferRowIndex targetBufferRow = crumbs.evaluateAsForwardChain(singleSelectedRow); + enableAction &= targetBufferRow.isValid(); + } + + editOtherAction->setEnabled(enableAction); + } + QString deleteString = tr("Delete") + (Settings::confirmDelete.get() ? "..." : ""); tableContextMenuDeleteAction->setText(deleteString); @@ -559,3 +600,33 @@ void MainWindowTabContent::handle_removeCustomColumn() filterBar->compColumnAboutToBeRemoved(compTable->getColumnAt(logicalIndex)); compTable->removeCustomColumnAt(logicalIndex); } + + + +// HELPERS + +QList MainWindowTabContent::getDirectlyReferencedTypes() const +{ + QList> forwardOnlyCrumbs = QList>(); + + for (const ItemTypeMapper* const otherMapper : typesHandler->getAllMappers()) { + if (otherMapper == mapper) continue; + + const Breadcrumbs crumbs = db->getBreadcrumbsFor(mapper->baseTable, otherMapper->baseTable); + if (crumbs.isForwardOnly()) { + forwardOnlyCrumbs.append({otherMapper->type, crumbs}); + } + } + + std::vector> vector = std::vector>(forwardOnlyCrumbs.begin(), forwardOnlyCrumbs.end()); + auto comparator = [](const QPair& p1, const QPair& p2) { + return p1.second.length() < p2.second.length(); + }; + std::stable_sort(vector.begin(), vector.end(), comparator); + + QList result = QList(); + for (const auto& [type, _] : vector) { + result.append(type); + } + return result; +} diff --git a/src/main/main_window_tab_content.h b/src/main/main_window_tab_content.h index 613f12d..4de588b 100644 --- a/src/main/main_window_tab_content.h +++ b/src/main/main_window_tab_content.h @@ -24,6 +24,7 @@ #ifndef MAIN_WINDOW_TAB_CONTENT_H #define MAIN_WINDOW_TAB_CONTENT_H +#include "src/data/item_types.h" #include "ui_main_window_tab.h" #include @@ -35,9 +36,11 @@ class MainWindowTabContent : public QWidget, private Ui_MainWindowTabContent { Q_OBJECT - MainWindow* mainWindow; - ItemTypeMapper* mapper; - CompositeTable* compTable; + MainWindow* mainWindow; + const ItemTypesHandler* typesHandler; + ItemTypeMapper* mapper; + Database* db; + CompositeTable* compTable; bool isViewable; bool isDuplicable; @@ -62,6 +65,8 @@ class MainWindowTabContent : public QWidget, private Ui_MainWindowTabContent QAction* tableContextMenuEditAction; /** The context menu entry for duplicating the selected item. */ QAction* tableContextMenuDuplicateAction; + /** The context menu entries and their target item types for editing directly referenced items. */ + QList> tableContextMenuEditOtherActions; /** The context menu entry for deleting the selected items. */ QAction* tableContextMenuDeleteAction; @@ -73,7 +78,7 @@ class MainWindowTabContent : public QWidget, private Ui_MainWindowTabContent ~MainWindowTabContent(); // Initial setup - void init(MainWindow* mainWindow, ItemTypeMapper* mapper, bool viewable, bool duplicable); + void init(MainWindow* mainWindow, const ItemTypesHandler* typesHandler, ItemTypeMapper* mapper, Database& db, bool viewable, bool duplicable); void restoreColumnWidths(); void restoreColumnOrder(); void restoreColumnHiddenStatus(); @@ -103,6 +108,10 @@ private slots: void handle_addCustomColumn(); void handle_columnWizardAccepted(); void handle_removeCustomColumn(); + +private: + // Helpers + QList getDirectlyReferencedTypes() const; }; diff --git a/src/viewer/ascent_viewer.cpp b/src/viewer/ascent_viewer.cpp index 6ae60db..07f71a3 100644 --- a/src/viewer/ascent_viewer.cpp +++ b/src/viewer/ascent_viewer.cpp @@ -197,9 +197,9 @@ void AscentViewer::connectUI() */ void AscentViewer::setupContextMenus() { - editAscentAction = infoContextMenu.addAction(tr("Edit ascent..."), this, &AscentViewer::handle_editAscent); - editPeakAction = infoContextMenu.addAction(tr("Edit peak..."), this, &AscentViewer::handle_editPeak); - editTripAction = infoContextMenu.addAction(tr("Edit trip..."), this, &AscentViewer::handle_editTrip); + editAscentAction = infoContextMenu.addAction(db.ascentsTable.getEditItemString(), this, &AscentViewer::handle_editAscent); + editPeakAction = infoContextMenu.addAction(db.peaksTable.getEditItemString(), this, &AscentViewer::handle_editPeak); + editTripAction = infoContextMenu.addAction(db.tripsTable.getEditItemString(), this, &AscentViewer::handle_editTrip); editAscentAction ->setIcon(QIcon(":/icons/ascent.svg")); editPeakAction ->setIcon(QIcon(":/icons/peak.svg")); diff --git a/translation/de.ts b/translation/de.ts index 3d8af6b..ee4d76c 100644 --- a/translation/de.ts +++ b/translation/de.ts @@ -548,21 +548,6 @@ Soll sie trotzdem verwendet werden? Remove photo Angezeigtes Foto entfernen - - - Edit ascent... - Besteigung bearbeiten... - - - - Edit peak... - Gipfel bearbeiten... - - - - Edit trip... - Urlaub bearbeiten... - @@ -698,17 +683,22 @@ Die Datei kann entfernt oder ersetzt werden. Alternativ können mit einem Werkze Keine - + + Edit ascent... + Besteigung bearbeiten... + + + New custom column for ascents Neue benutzerdefinierte Spalte für Besteigungen - + New ascent filter Neuer Besteigungs-Filter - + %Ln ascent(s) %Ln Besteigung @@ -716,12 +706,12 @@ Die Datei kann entfernt oder ersetzt werden. Alternativ können mit einem Werkze - + Saved new ascent. Neue Besteigung gespeichert. - + Saved changes in %Ln ascent(s). Änderungen in Besteigung gespeichert. @@ -729,7 +719,7 @@ Die Datei kann entfernt oder ersetzt werden. Alternativ können mit einem Werkze - + Deleted %Ln ascent(s). Besteigung gelöscht. @@ -1244,17 +1234,22 @@ Jede Tabelle hat einen fett gedruckten Eintrag. Dieser kann jeweils für die Anw Keines - + + Edit country... + Land bearbeiten... + + + New custom column for countries Neue benutzerdefinierte Spalte für Länder - + New country filter Neuer Landes-Filter - + %Ln country/countries %Ln Land @@ -1262,12 +1257,12 @@ Jede Tabelle hat einen fett gedruckten Eintrag. Dieser kann jeweils für die Anw - + Saved new country. Neues Land gespeichert. - + Saved changes in %Ln country/countries. Änderungen in Land gespeichert. @@ -1275,7 +1270,7 @@ Jede Tabelle hat einen fett gedruckten Eintrag. Dieser kann jeweils für die Anw - + Deleted %Ln country/countries. Land gelöscht. @@ -2107,7 +2102,7 @@ Hinweis: Vor dem Bestätigen kann die Datei auch noch manuell gesichert werden.< Filterung aufheben - + Hidden columns Ausgeblendete Spalten @@ -2396,17 +2391,22 @@ Hinweis: Vor dem Bestätigen kann die Datei auch noch manuell gesichert werden.< Keiner - + + Edit hiker... + Wanderer bearbeiten... + + + New custom column hikers Neue benutzerdefinierte Spalte für Wanderer - + New hiker filter Neuer Wanderer-Filter - + %Ln hiker(s) %Ln Wanderer @@ -2414,12 +2414,12 @@ Hinweis: Vor dem Bestätigen kann die Datei auch noch manuell gesichert werden.< - + Saved new hiker. Neuer Wanderer gespeichert. - + Saved changes in %Ln hiker(s). Änderungen in Wanderer gespeichert. @@ -2427,7 +2427,7 @@ Hinweis: Vor dem Bestätigen kann die Datei auch noch manuell gesichert werden.< - + Deleted %Ln hiker(s). Wanderer gelöscht. @@ -2860,64 +2860,64 @@ Trotzdem speichern? Keine Filter aktiv - + Updating table Tabelle wird aktualisiert - + Updating table... Tabelle wird aktualisiert... - + Save new database as Neue Datenbank speichern unter - + Open database Datenbank öffnen - + Database files Datanbank-Dateien - + All files Alle Dateien - - + + Save database as Datenbank speichern unter - + You cannot Save As to the same file. Datenbank kann nicht unter dem selben Namen gsepeichert werden. - + Hint: Hinweis: - + PAL auto-saves every change you make immediately, there is no need to save manually. PAL sichert automatisch alle Änderungen sofort. Manuelles Speichern ist nicht nötig. - + Writing database file failed: Speichern der neuen Datenbank-Datei fehlgeschlagen: - + Reverting to previously opened file: Kehre zurück zu vorher geöffneter Datei: @@ -2945,23 +2945,23 @@ Trotzdem speichern? Benutzerdefinierte Spalte hinzufügen... - + View... Ansehen... - + Edit... Bearbeiten... - + Edit as new duplicate... Als neues Duplikat bearbeiten... - - + + Delete Löschen @@ -3234,17 +3234,22 @@ Trotzdem speichern? Keiner - + + Edit peak... + Gipfel bearbeiten... + + + New custom column for peaks Neue benutzerdefinierte Spalte für Gipfel - + New peak filter Neuer Gipfel-Filter - + %Ln peak(s) %Ln Gipfel @@ -3252,12 +3257,12 @@ Trotzdem speichern? - + Saved new peak. Neuer Gipfel gespeichert. - + Saved changes in %Ln peak(s). Änderungen in Gipfel gespeichert. @@ -3265,7 +3270,7 @@ Trotzdem speichern? - + Deleted %Ln peak(s). Gipfel gelöscht. @@ -3321,17 +3326,22 @@ Trotzdem speichern? Keines - + + Edit photo... + Foto bearbeiten... + + + New custom column for photos Neue benutzerdefinierte Spalte für Fotos - + New photo filter Neuer Foto-Filter - + %Ln photo(s) %Ln Foto @@ -3339,7 +3349,7 @@ Trotzdem speichern? - + Saved new photo. Neues Foto gespeichert. @@ -3349,7 +3359,7 @@ Trotzdem speichern? Foto #%1 - + Saved changes in %Ln photo(s). Änderungen in Foto gespeichert. @@ -3357,7 +3367,7 @@ Trotzdem speichern? - + Deleted %Ln photo(s). Foto gelöscht. @@ -3490,8 +3500,13 @@ Trotzdem speichern? None Keines + + + Edit mountain range... + Gebirge bearbeiten... + - + Saved changes in %Ln mountain range(s). Änderungen in Gebirge gespeichert. @@ -3499,7 +3514,7 @@ Trotzdem speichern? - + Deleted %Ln mountain range(s). Gebirge gelöscht. @@ -3507,17 +3522,17 @@ Trotzdem speichern? - + New custom column for mountain ranges Neue benutzerdefinierte Spalte für Gebirge - + New mountain range filter Neuer Gebirgs-Filter - + %Ln mountain range(s) %Ln Gebirge @@ -3525,7 +3540,7 @@ Trotzdem speichern? - + Saved new mountain range. Neues Gebirge gespeichert. @@ -3649,17 +3664,22 @@ Trotzdem speichern? Keine - + + Edit region... + Region bearbeiten... + + + New custom column for regions Neue benutzerdefinierte Spalte für Regionen - + New region filter Neuer Regions-Filter - + %Ln region(s) %Ln Region @@ -3667,12 +3687,12 @@ Trotzdem speichern? - + Saved new region. Neue Region gespeichert. - + Saved changes in %Ln region(s). Änderungen in Region gespeichert. @@ -3680,7 +3700,7 @@ Trotzdem speichern? - + Deleted %Ln region(s). Region gelöscht. @@ -4102,17 +4122,22 @@ Trotzdem speichern? Keiner - + + Edit trip... + Urlaub bearbeiten... + + + New custom column for trips Neue benutzerdefinierte Spalte für Urlaube - + New trip filter Neuer Urlaubs-Filter - + %Ln trip(s) %Ln Urlaub @@ -4120,12 +4145,12 @@ Trotzdem speichern? - + Saved new trip. Neuer Urlaub gespeichert. - + Saved changes in %Ln trip(s). Änderungen in Urlaub gespeichert. @@ -4133,7 +4158,7 @@ Trotzdem speichern? - + Deleted %Ln trip(s). Urlaub gelöscht. diff --git a/translation/en.ts b/translation/en.ts index 5cbfe87..a29d597 100644 --- a/translation/en.ts +++ b/translation/en.ts @@ -23,7 +23,7 @@ AscentsTable - + Saved changes in %Ln ascent(s). Saved changes in ascent. @@ -31,7 +31,7 @@ - + Deleted %Ln ascent(s). Deleted ascent. @@ -39,7 +39,7 @@ - + %Ln ascent(s) %Ln ascent @@ -50,7 +50,7 @@ CountriesTable - + Saved changes in %Ln country/countries. Saved changes in country. @@ -58,7 +58,7 @@ - + Deleted %Ln country/countries. Deleted country. @@ -66,7 +66,7 @@ - + %Ln country/countries %Ln country @@ -115,7 +115,7 @@ HikersTable - + Saved changes in %Ln hiker(s). Saved changes in hiker. @@ -123,7 +123,7 @@ - + Deleted %Ln hiker(s). Deleted hiker. @@ -131,7 +131,7 @@ - + %Ln hiker(s) %Ln hiker @@ -161,7 +161,7 @@ PeaksTable - + Saved changes in %Ln peak(s). Saved changes in peak. @@ -169,7 +169,7 @@ - + Deleted %Ln peak(s). Deleted peak. @@ -177,7 +177,7 @@ - + %Ln peak(s) %Ln peak @@ -188,7 +188,7 @@ PhotosTable - + Saved changes in %Ln photo(s). Saved changes in photo. @@ -196,7 +196,7 @@ - + Deleted %Ln photo(s). Deleted photo. @@ -204,7 +204,7 @@ - + %Ln photo(s) %Ln photo @@ -234,7 +234,7 @@ RangesTable - + Saved changes in %Ln mountain range(s). Saved changes in mountain range. @@ -242,7 +242,7 @@ - + Deleted %Ln mountain range(s). Deleted mountain range. @@ -250,7 +250,7 @@ - + %Ln mountain range(s) %Ln mountain range @@ -280,7 +280,7 @@ RegionsTable - + Saved changes in %Ln region(s). Saved changes in region. @@ -288,7 +288,7 @@ - + Deleted %Ln region(s). Deleted region. @@ -296,7 +296,7 @@ - + %Ln region(s) %Ln region @@ -326,7 +326,7 @@ TripsTable - + Saved changes in %Ln trip(s). Saved changes in trip. @@ -334,7 +334,7 @@ - + Deleted %Ln trip(s). Deleted trip. @@ -342,7 +342,7 @@ - + %Ln trip(s) %Ln trip