Skip to content

Commit

Permalink
Add indirect edit actions to table context menus
Browse files Browse the repository at this point in the history
Closes #217
  • Loading branch information
svetter committed Jul 30, 2024
1 parent f876994 commit 1fae92b
Show file tree
Hide file tree
Showing 24 changed files with 368 additions and 138 deletions.
8 changes: 8 additions & 0 deletions src/db/normal_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/ascents_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/ascents_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/countries_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/countries_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/hikers_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/hikers_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/peaks_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/peaks_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/photos_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/photos_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/ranges_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/ranges_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/regions_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/regions_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/db/tables_spec/trips_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/db/tables_spec/trips_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 31 additions & 3 deletions src/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
};
Expand All @@ -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<BufferRowIndex>& 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.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1fae92b

Please sign in to comment.