Skip to content

Commit c0a4a67

Browse files
committed
Enable hiding and re-adding columns
Includes all settings, saving and restoring, and translation. Missing optimization for not updating hidden columns. For #129
1 parent d8dab94 commit c0a4a67

9 files changed

+376
-155
lines changed

src/main/item_types_handler.h

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class ItemTypeMapper {
102102
ProjectMultiSetting<int>* const columnWidthsSetting;
103103
/** The setting storing the column order for the UI table of this item type. */
104104
ProjectMultiSetting<int>* const columnOrderSetting;
105+
/** The setting storing the column hidden states for the UI table of this item type. */
106+
ProjectMultiSetting<bool>* const hiddenColumnsSetting;
105107
/** The setting storing the sorting of the UI table of this item type. */
106108
const ProjectSetting<QString>* const sortingSetting;
107109

@@ -154,6 +156,7 @@ class ItemTypeMapper {
154156
QPushButton* const newItemButton,
155157
ProjectMultiSetting<int>* columnWidthsSetting,
156158
ProjectMultiSetting<int>* columnOrderSetting,
159+
ProjectMultiSetting<bool>* hiddenColumnsSetting,
157160
const ProjectSetting<QString>* sortingSetting,
158161
const Setting<QRect>* dialogGeometrySetting,
159162
BufferRowIndex (* const openNewItemDialogAndStoreMethod) (QWidget*, Database*),
@@ -173,6 +176,7 @@ class ItemTypeMapper {
173176
dialogGeometrySetting (dialogGeometrySetting),
174177
columnWidthsSetting (columnWidthsSetting),
175178
columnOrderSetting (columnOrderSetting),
179+
hiddenColumnsSetting (hiddenColumnsSetting),
176180
sortingSetting (sortingSetting),
177181
openNewItemDialogAndStoreMethod (openNewItemDialogAndStoreMethod),
178182
openDuplicateItemDialogAndStoreMethod (openDuplicateItemDialogAndStoreMethod),
@@ -225,6 +229,7 @@ class ItemTypeMapper {
225229
QPushButton* const newItemButton, \
226230
ProjectMultiSetting<int>* columnWidthsSetting, \
227231
ProjectMultiSetting<int>* columnOrderSetting, \
232+
ProjectMultiSetting<bool>* hiddenColumnsSetting, \
228233
const ProjectSetting<QString>* sortingSetting
229234

230235
/**
@@ -239,6 +244,7 @@ class ItemTypeMapper {
239244
newItemButton, \
240245
columnWidthsSetting, \
241246
columnOrderSetting, \
247+
hiddenColumnsSetting, \
242248
sortingSetting
243249

244250

src/main/main_window.cpp

+200-65
Large diffs are not rendered by default.

src/main/main_window.h

+22-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ class MainWindow : public QMainWindow, public Ui_MainWindow
5353
Database db;
5454
/** The list of menu items for opening the most recently opened database files. */
5555
QList<QAction*> openRecentActions;
56-
/** The context menu for the UI tables. */
56+
57+
/** The context menu for the column header area of all UI tables. */
58+
QMenu columnContextMenu;
59+
/** The column context menu entry for hiding the selected column. */
60+
QAction* columnContextMenuHideColumnAction;
61+
/** The column context submenu for unhiding any previously hidden column. */
62+
QMenu* columnContextMenuRestoreColumnMenu;
63+
64+
/** The context menu for the cell are of all UI tables. */
5765
QMenu tableContextMenu;
5866
/** The context menu entry for opening the selected item. */
5967
QAction* tableContextMenuOpenAction;
@@ -63,8 +71,10 @@ class MainWindow : public QMainWindow, public Ui_MainWindow
6371
QAction* tableContextMenuDuplicateAction;
6472
/** The context menu entry for deleting the selected items. */
6573
QAction* tableContextMenuDeleteAction;
74+
6675
/** List of keyboard shortcuts. */
6776
QList<QShortcut*> shortcuts;
77+
6878
/** The status bar label for the current table size. */
6979
QLabel* statusBarTableSizeLabel;
7080
/** The status bar label for the current filter settings. */
@@ -94,9 +104,11 @@ class MainWindow : public QMainWindow, public Ui_MainWindow
94104
void setupDebugTableViews();
95105
void restoreColumnWidths(const ItemTypeMapper* const mapper);
96106
void restoreColumnOrder(const ItemTypeMapper* const mapper);
107+
void restoreColumnHiddenStatus(const ItemTypeMapper* const mapper);
97108
void setSorting(const ItemTypeMapper* const mapper);
109+
void initColumnContextMenu();
98110
void initTableContextMenuAndShortcuts();
99-
void updateContextMenuEditIcon();
111+
void updateTableContextMenuIcons();
100112

101113
// Project setup (on load)
102114
void attemptToOpenFile(const QString& filepath);
@@ -124,9 +136,13 @@ class MainWindow : public QMainWindow, public Ui_MainWindow
124136
private slots:
125137
// UI event handlers
126138
void handle_tabChanged();
127-
void handle_rightClick(QPoint pos);
139+
void handle_rightClickOnColumnHeader(QPoint pos);
140+
void handle_rightClickInTable(QPoint pos);
128141

129-
// Context menu action handlers
142+
// Column context menu action handlers
143+
void handle_hideColumn();
144+
void handle_unhideColumn();
145+
// Table context menu action handlers
130146
void handle_viewSelectedItem();
131147
void handle_editSelectedItem();
132148
void handle_duplicateAndEditSelectedItem();
@@ -145,6 +161,7 @@ private slots:
145161
void handle_showFiltersChanged();
146162
void handle_autoResizeColumns();
147163
void handle_resetColumnOrder();
164+
void handle_restoreHiddenColumns();
148165
// Tools menu action handlers
149166
void handle_relocatePhotos();
150167
void handle_exportData();
@@ -156,8 +173,7 @@ private slots:
156173
void closeEvent(QCloseEvent* event) override;
157174
void saveProjectImplicitSettings();
158175
void saveGlobalImplicitSettings();
159-
void saveColumnWidths(const ItemTypeMapper* const mapper);
160-
void saveColumnOrder(const ItemTypeMapper* const mapper);
176+
void saveImplicitColumnSettings(const ItemTypeMapper* const mapper);
161177
void saveSorting(const ItemTypeMapper* const mapper);
162178
// Layout changes
163179
virtual void resizeEvent(QResizeEvent* event) override;

src/settings/project_settings.h

+26
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class ProjectMultiSetting
113113

114114
// List used types as compiler hints
115115
template class ProjectMultiSetting<int>;
116+
template class ProjectMultiSetting<bool>;
116117

117118

118119

@@ -170,6 +171,22 @@ class ProjectSettings {
170171
/** Remembered column order of the countries table in the main window. */
171172
ProjectMultiSetting<int> columnOrder_countriesTable;
172173

174+
// Hidden columns
175+
/** Remembered column hidden states of the ascents table in the main window. */
176+
ProjectMultiSetting<bool> hiddenColumns_ascentsTable;
177+
/** Remembered column hidden states of the peaks table in the main window. */
178+
ProjectMultiSetting<bool> hiddenColumns_peaksTable;
179+
/** Remembered column hidden states of the trips table in the main window. */
180+
ProjectMultiSetting<bool> hiddenColumns_tripsTable;
181+
/** Remembered column hidden states of the hikers table in the main window. */
182+
ProjectMultiSetting<bool> hiddenColumns_hikersTable;
183+
/** Remembered column hidden states of the regions table in the main window. */
184+
ProjectMultiSetting<bool> hiddenColumns_regionsTable;
185+
/** Remembered column hidden states of the ranges table in the main window. */
186+
ProjectMultiSetting<bool> hiddenColumns_rangesTable;
187+
/** Remembered column hidden states of the countries table in the main window. */
188+
ProjectMultiSetting<bool> hiddenColumns_countriesTable;
189+
173190
// Sorting
174191
/** Remembered sorting of the ascents table in the main window. */
175192
ProjectSetting<QString> sorting_ascentsTable;
@@ -250,6 +267,15 @@ class ProjectSettings {
250267
columnOrder_rangesTable (ProjectMultiSetting<int> (table, "implicit/mainWindow/columnOrder/rangesTable", -1)),
251268
columnOrder_countriesTable (ProjectMultiSetting<int> (table, "implicit/mainWindow/columnOrder/countriesTable", -1)),
252269

270+
// Column widths
271+
hiddenColumns_ascentsTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/ascentsTable", false)),
272+
hiddenColumns_peaksTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/peaksTable", false)),
273+
hiddenColumns_tripsTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/tripsTable", false)),
274+
hiddenColumns_hikersTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/hikersTable", false)),
275+
hiddenColumns_regionsTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/regionsTable", false)),
276+
hiddenColumns_rangesTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/rangesTable", false)),
277+
hiddenColumns_countriesTable (ProjectMultiSetting<bool> (table, "implicit/mainWindow/hiddenColumns/countriesTable", false)),
278+
253279
// Sorting
254280
sorting_ascentsTable (ProjectSetting<QString> (table, "implicit/mainWindow/sorting/ascentsTable")),
255281
sorting_peaksTable (ProjectSetting<QString> (table, "implicit/mainWindow/sorting/peaksTable")),

src/settings/settings.h

+2
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ class Settings {
331331
inline static const Setting<bool> rememberColumnWidths = Setting<bool> ("rememberColumnWidths", true);
332332
/** Remember the column order of all tables in the main window. */
333333
inline static const Setting<bool> rememberColumnOrder = Setting<bool> ("rememberColumnOrder", true);
334+
/** Remember which columns are hidden in all tables in the main window. */
335+
inline static const Setting<bool> rememberHiddenColumns = Setting<bool> ("rememberHiddenColumns", true);
334336
/** Remember the sorting of all tables in the main window. */
335337
inline static const Setting<bool> rememberSorting = Setting<bool> ("rememberSorting", true);
336338
/** Remember the active filters of all tables in the main window. */

src/settings/settings_window.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void SettingsWindow::loadSettings()
9292
rememberTableCheckbox ->setChecked (rememberTab .get());
9393
rememberColumnWidthsCheckbox ->setChecked (rememberColumnWidths .get());
9494
rememberColumnOrderCheckbox ->setChecked (rememberColumnOrder .get());
95+
rememberHiddenColumnsCheckbox ->setChecked (rememberHiddenColumns .get());
9596
rememberSortingCheckbox ->setChecked (rememberSorting .get());
9697
rememberFiltersCheckbox ->setChecked (rememberFilters .get());
9798

@@ -129,6 +130,7 @@ void SettingsWindow::loadDefaults()
129130
rememberTableCheckbox ->setChecked (rememberTab .getDefault());
130131
rememberColumnWidthsCheckbox ->setChecked (rememberColumnWidths .getDefault());
131132
rememberColumnOrderCheckbox ->setChecked (rememberColumnOrder .getDefault());
133+
rememberHiddenColumnsCheckbox ->setChecked (rememberHiddenColumns .getDefault());
132134
rememberSortingCheckbox ->setChecked (rememberSorting .getDefault());
133135
rememberFiltersCheckbox ->setChecked (rememberFilters .getDefault());
134136

@@ -171,6 +173,7 @@ void SettingsWindow::saveSettings()
171173
rememberTab .set(rememberTableCheckbox ->isChecked());
172174
rememberColumnWidths .set(rememberColumnWidthsCheckbox ->isChecked());
173175
rememberColumnOrder .set(rememberColumnOrderCheckbox ->isChecked());
176+
rememberHiddenColumns .set(rememberHiddenColumnsCheckbox ->isChecked());
174177
rememberSorting .set(rememberSortingCheckbox ->isChecked());
175178
rememberFilters .set(rememberFiltersCheckbox ->isChecked());
176179

src/ui/main_window.ui

+6
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@
786786
<addaction name="separator"/>
787787
<addaction name="autoResizeColumnsAction"/>
788788
<addaction name="resetColumnOrderAction"/>
789+
<addaction name="restoreHiddenColumnsAction"/>
789790
</widget>
790791
<widget class="QMenu" name="newMenu">
791792
<property name="title">
@@ -981,6 +982,11 @@
981982
<string>Reset column order</string>
982983
</property>
983984
</action>
985+
<action name="restoreHiddenColumnsAction">
986+
<property name="text">
987+
<string>Restore hidden columns</string>
988+
</property>
989+
</action>
984990
</widget>
985991
<customwidgets>
986992
<customwidget>

src/ui/settings_window.ui

+13-6
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,31 @@
251251
</property>
252252
</widget>
253253
</item>
254-
<item row="1" column="0">
254+
<item row="2" column="0">
255+
<widget class="QCheckBox" name="rememberSortingCheckbox">
256+
<property name="text">
257+
<string>Sorting</string>
258+
</property>
259+
</widget>
260+
</item>
261+
<item row="0" column="1">
255262
<widget class="QCheckBox" name="rememberColumnWidthsCheckbox">
256263
<property name="text">
257264
<string>Column widths</string>
258265
</property>
259266
</widget>
260267
</item>
261-
<item row="2" column="0">
262-
<widget class="QCheckBox" name="rememberSortingCheckbox">
268+
<item row="1" column="0">
269+
<widget class="QCheckBox" name="rememberColumnOrderCheckbox">
263270
<property name="text">
264-
<string>Sorting</string>
271+
<string>Column order</string>
265272
</property>
266273
</widget>
267274
</item>
268275
<item row="1" column="1">
269-
<widget class="QCheckBox" name="rememberColumnOrderCheckbox">
276+
<widget class="QCheckBox" name="rememberHiddenColumnsCheckbox">
270277
<property name="text">
271-
<string>Column order</string>
278+
<string>Hidden columns</string>
272279
</property>
273280
</widget>
274281
</item>

0 commit comments

Comments
 (0)