Filter Panel Functionality
Relevant source files
The following files were used as context for generating this wiki page:
The Filter Panel Functionality provides a robust mechanism for users to refine search results within the SSA Consulta Rapida Cpp application. It allows for multi-faceted filtering, including quick sector selection, exclusion of specific administrative statuses (SCA/SES/STE), and custom column-based filters. This module acts as the bridge between the UI interaction layer and the SQL query generation logic.
The architecture follows a Model-View-ViewModel (MVVM) pattern where the FilterPanelViewModel manages the state of active filters and communicates changes to the MainViewModel to trigger data refreshes. The system ensures that all filters are compiled into efficient SQL WHERE clauses before execution against the SQLite database.
Sources: src/presentation/FilterPanelViewModel.cpp, src/presentation/MainViewModel.cpp:210-220
Core Components and Architecture
The filtering logic is distributed across three main layers: Presentation, Domain, and Query.
FilterPanelViewModel
The FilterPanelViewModel class is the central coordinator for the filter UI. It maintains the current state of selected columns, filter values, and toggle states (such as the exclusion of SCA/SES/STE records). It uses a "lazy" update strategy, marking active filters as "dirty" whenever a change occurs and rebuilding the summary only when requested by the view.
Key properties include:
quickSector: A specific sector string to filter bysetor_executor.excludeScaSesSte: A boolean flag to omit specific record statuses.columnFilters: A map of column keys to their respective filter values.
Sources: src/presentation/FilterPanelViewModel.h:18-28, src/presentation/FilterPanelViewModel.cpp:113-131
Filter Data Flow
The following diagram illustrates how filter changes propagate from the UI through the ViewModels to the SQL generation layer.
The interaction starts with user input in the UI, which updates the FilterPanelViewModel. This triggers an update in the MainViewModel, which constructs an SsaPageRequest object containing all active filter criteria.
Sources: src/presentation/MainViewModel.cpp:189-200, src/query/SqlQueryBuilder.cpp:125-155
Filtering Logic and Rules
Automatic Status Exclusion
By default, the system is configured to exclude records with statuses "SCA", "SES", or "STE". This is managed by the excludeScaSesSte flag. When active, the SqlQueryBuilder appends a specific clause to the SQL: UPPER(COALESCE("situacao", '')) NOT IN ('SCA', 'SES', 'STE').
Sources: src/domain/SsaTypes.h:20, src/query/SqlQueryBuilder.cpp:150-153
Filter Summary Generation
To provide feedback to the user, the system generates a human-readable summary of active filters. This is handled by domain utility functions that join different filter parts using a separator (default is |).
| Filter Type | Internal Key | Display Format Example |
|---|---|---|
| Quick Sector | setor_executor | setor_executor:IEE3 |
| Status Exclusion | N/A | sem SCA/SES/STE |
| Column Filter | Variable | situacao:APV |
Sources: src/domain/SsaTypes.h:35-50, src/presentation/FilterPanelViewModel.cpp:100-111
SQL Compilation
Filters are compiled into SQL using parameterized queries to ensure security and performance. The SqlQueryBuilder processes each column filter by parsing the text into FilterTerms and mapping them to SQL operators like LIKE, =, or REGEXP.
Key Implementation Details
Filter Initialization
During construction, the FilterPanelViewModel populates available filter keys from the ColumnCatalog and sets the default filter column (usually situacao).
// src/presentation/FilterPanelViewModel.cpp:11-17
FilterPanelViewModel::FilterPanelViewModel(QObject* parent) : QObject(parent) {
for (const auto& key : domain::ColumnCatalog::filterColumnKeys()) {
filterColumnKeys_.push_back(QString::fromStdString(key));
}
columnKey_ = QString::fromStdString(domain::ColumnCatalog::defaultFilterColumnKey());
markActiveFiltersDirty();
}
Sources: src/presentation/FilterPanelViewModel.cpp:11-17, src/domain/ColumnCatalog.cpp:113-115
Adding and Resetting Filters
Adding a filter involves trimming the input and adding it to the columnFilters map. Resetting the panel restores default values, such as the excludeScaSesSte flag defined in the domain types.
// src/presentation/FilterPanelViewModel.cpp:88-98
void FilterPanelViewModel::resetFilters() {
quickSector_.clear();
columnKey_ = QString::fromStdString(domain::ColumnCatalog::defaultFilterColumnKey());
columnValue_.clear();
columnFilters_.clear();
excludeScaSesSte_ = domain::kDefaultExcludeScaSesSte;
markActiveFiltersDirty();
emit changed();
emit applyRequested();
}
Sources: src/presentation/FilterPanelViewModel.cpp:88-98, src/domain/SsaTypes.h:20
Summary
The Filter Panel Functionality is a critical component for data navigation in the SSA Consulta Rapida Cpp project. By utilizing a structured MVVM approach and offloading SQL generation to a dedicated builder, it provides a flexible yet performant way to query complex datasets. The integration with the ColumnCatalog ensures that filtering remains consistent with the underlying data schema.