Column Settings & Customization
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Column Settings & Customization system allows users to manage how data is presented within the application's main table. This module provides functionality to toggle column visibility, adjust column widths, and filter the list of available columns. It ensures that user preferences are persisted across sessions and applied to the data retrieval process.
This system bridges the gap between the static data definitions in the ColumnCatalog and the dynamic user interface. By managing visibility and width through a dedicated ColumnSettingsModel, the application can optimize SQL queries to only fetch necessary data while providing a responsive user experience.
Sources: src/presentation/MainViewModel.cpp:160-170, src/presentation/ColumnSettingsModel.cpp:20-30
Architecture and Components
The system follows a Model-View-ViewModel (MVVM) pattern where the ColumnSettingsModel acts as a specialized list model for the settings UI, and MainViewModel coordinates the application of these settings to the actual data table.
Key Components
| Component | Responsibility |
|---|---|
ColumnCatalog | Static repository of all available columns, their default visibility, types, and labels. |
ColumnSettingsModel | A QAbstractListModel that manages the state of column customization (visibility, width) for the UI. |
MainViewModel | Orchestrates the application and discarding of settings, and triggers data reloads when visibility changes. |
SsaTableModel | Receives the finalized column configuration to render the data grid correctly. |
Sources: src/domain/ColumnCatalog.h:20-30, src/presentation/ColumnSettingsModel.h:17-30, src/presentation/MainViewModel.h:50-70
Class Relationship Diagram
The following diagram illustrates how the customization components interact with each other and the domain catalog.
Data Flow and Logic
Configuration Lifecycle
- Initialization: Upon startup, the
MainViewModelloads user preferences (if any) and instructs theColumnSettingsModelto apply these settings. - Modification: The user interacts with the customization UI, calling
setColumnVisibleorsetColumnWidthon theColumnSettingsModel. These changes are local to the settings model until applied. - Application: When the user clicks "Apply",
MainViewModel::applyColumnSettings()fetches the visible keys and widths from the settings model, updates theSsaTableModel, and saves the preferences to disk.
Sources: src/presentation/MainViewModel.cpp:40-50, src/presentation/MainViewModel.cpp:218-230
Column Filtering and Visibility Logic
The ColumnSettingsModel includes a filtering mechanism that allows users to search for specific columns by name or key. This is implemented via a proxy-like behavior using filteredRows_ and sourceToModelRow_ vectors.
Constraints and Validation
To maintain UI integrity, the system enforces several constraints:
- Minimum/Maximum Width: Column widths are clamped between 80 and 520 pixels.
- Minimum Visible Columns: The system prevents users from hiding all columns; at least one column must remain visible.
- Toggle State: The
ToggleEnabledRoleprovides a hint to the UI to disable the "hide" checkbox if only one column is currently visible.
Sources: src/presentation/ColumnSettingsModel.cpp:11-13, src/presentation/ColumnSettingsModel.cpp:100-110, src/presentation/ColumnSettingsModel.cpp:200-205
Implementation Details
Column Definition Structure
The ColumnDef struct in the domain layer defines the metadata for every column in the system.
struct ColumnDef {
std::string key; // Internal database identifier
std::string label; // UI display name
ColumnType type; // Data type (Text, Integer, etc.)
bool defaultVisible; // Initial visibility state
bool generalSearch; // Included in global search?
int defaultWidth; // Default UI width
};
Sources: src/domain/ColumnCatalog.h:18-25
Applying Customization
When applyColumnSettings is invoked, the system determines if a data reload is necessary. A reload is triggered only if the list of visible columns has changed, as changing widths only affects the presentation layer.
Summary
The Column Settings & Customization system provides a robust framework for managing user-defined table views. By separating the static catalog from a dynamic settings model, the application maintains a clear distinction between domain data requirements and user presentation preferences. Key features include persistent storage of widths and visibility, real-time filtering of settings, and optimized data fetching based on the active column set.
Sources: src/presentation/MainViewModel.cpp:232-235, src/presentation/ColumnSettingsModel.cpp:270-275