LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
ui::qt::EventsTableModel Class Reference

#include <EventsTableModel.hpp>

Inheritance diagram for ui::qt::EventsTableModel:
Inheritance graph
Collaboration diagram for ui::qt::EventsTableModel:
Collaboration graph

Classes

struct  ColumnFilter
 
struct  PrunedColumnState
 
struct  SortKey
 Sort key of one row, computed once (see SortIndices / SortBefore). More...
 

Signals

void ColumnFiltersChanged ()
 
void SearchMatchesChanged ()
 Search matches were recomputed after the row set changed.
 

Public Member Functions

 EventsTableModel (db::EventsContainer &events, QObject *parent=nullptr)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 
void SyncWithContainer ()
 
void RefreshAll ()
 
void RefreshColumns ()
 
void UpdateColors ()
 
void SetFilteredIndices (const std::vector< unsigned long > &indices)
 
void ClearFilter ()
 
const std::vector< unsigned long > & GetFilteredIndices () const
 
const std::vector< unsigned long > * GetBaseFilteredIndices () const
 
bool IsFilteringActive () const
 True if a filter is active — distinguishes "no filter" from "filter active, zero matches".
 
void SetSearchTerm (const QString &term, bool caseSensitive)
 
void SetSearchMode (utils::SearchMode mode)
 
int MatchCount () const
 
const std::vector< int > & MatchedRows () const
 
const utils::SearchEngine & GetSearchEngine () const
 
void RebuildSearchMatchesAsync ()
 Asynchronous search rebuild (doesn't block UI)
 
ColumnDistinctValues DistinctColumnValues (int column, std::size_t maxValues) const
 
QSet< QString > AllColumnValues (int column) const
 Distinct cell texts of column among all events, ignoring every filter.
 
bool HasColumnFilter (int column) const
 
bool HasAnyColumnFilter () const
 
bool HasActiveColumnFilter () const
 
QSet< QString > ColumnFilterValues (int column) const
 
bool IsColumnFilterExclusion (int column) const
 True if column's filter hides the listed values instead of showing them.
 
void SetColumnFilter (int column, const QSet< QString > &allowed)
 Restricts column to allowed (an empty set matches nothing).
 
void SetColumnFilterExcluding (int column, const QSet< QString > &excluded)
 
void ClearColumnFilter (int column)
 
void ClearColumnFilters ()
 
int ResolveToActualIndex (int row) const
 
int RowFromActualIndex (int actualIndex) const
 
std::vector< int > ColumnWidths () const
 
int ConfigIndexForColumn (int column) const
 
int ActiveSortColumn () const
 Model column of the active sort, or -1 if there is none or its column is hidden.
 
Qt::SortOrder ActiveSortOrder () const
 

Private Member Functions

bool ResolveColumn (int column, std::string &name, bool &mergeSource) const
 Resolves a model column to its data-column name / merge-source flag.
 
bool PassesColumnFilters (const db::LogEvent &event, const std::string *skipKey) const
 
void ApplyEffectiveFilter ()
 
void SortIndices (std::vector< unsigned long > &indices, const std::string &columnName, bool isMergeSource, Qt::SortOrder order) const
 
SortKey MakeSortKey (unsigned long idx, const std::string &columnName, bool isMergeSource) const
 
bool SortBefore (unsigned long a, unsigned long b) const
 True if row a sorts before row b in the active sort.
 
void AppendSortedRows (std::size_t total)
 
PrunedColumnState PruneStaleColumnState ()
 
bool BaseFilterIsStale () const
 
bool HasStaleIndices () const
 True if the upstream filter or the effective row list is stale.
 
void EndReset ()
 
void StoreColumnFilter (int column, const QSet< QString > &values, bool exclude)
 
void RebuildVisibleColumns ()
 
bool ShouldShowSourceColumn () const
 
bool ShouldShowOriginalIdColumn () const
 
QString ComposeCellText (const db::LogEvent &event, const std::string &columnName, bool mergeSource) const
 
QVariant GetSortValue (const db::LogEvent &event, const std::string &columnName, bool mergeSource) const
 
void RebuildSearchMatches ()
 

Static Private Member Functions

static std::string ColumnFilterKey (const std::string &name, bool mergeSource)
 
static int CompareSortKeys (const SortKey &a, const SortKey &b)
 Three-way ascending comparison of two keys (ties broken by event id).
 

Private Attributes

db::EventsContainer & m_events
 
std::vector< unsigned long > m_filteredIndices
 Effective rows (upstream ∩ column filters, sorted if m_hasSort)
 
std::vector< unsigned long > m_baseFilteredIndices
 Rows chosen by the rest of the app.
 
bool m_baseFilterActive {false}
 
std::uint64_t m_baseGeneration {0}
 container generation the upstream filter was set for
 
std::uint64_t m_indicesGeneration {0}
 container generation m_filteredIndices was built for
 
std::map< std::string, ColumnFilter > m_columnFilters
 
std::set< std::string > m_visibleFilterKeys
 Keys of the visible columns; only their filters apply.
 
bool m_hasSort {false}
 
std::size_t m_fullSortedCount {0}
 
std::string m_sortName
 sort column by data name, so it survives column changes
 
bool m_sortMergeSource {false}
 
Qt::SortOrder m_sortOrder {Qt::AscendingOrder}
 
std::unordered_map< unsigned long, int > m_reverseFilteredIndices
 
std::vector< int > m_visibleColumnIndices
 
const config::Config & m_config
 
bool m_hasSourceColumn {false}
 
bool m_filteringActive {false}
 
std::unique_ptr< utils::SearchEngine > m_searchEngine
 
QString m_searchTerm
 
bool m_searchCaseSensitive {false}
 
std::vector< int > m_matchedRows
 model row indices with at least one matching cell
 
std::unordered_set< int > m_matchedRowSet
 O(1) lookup used in data()
 

Constructor & Destructor Documentation

◆ EventsTableModel()

ui::qt::EventsTableModel::EventsTableModel ( db::EventsContainer &  events,
QObject *  parent = nullptr 
)
explicit
Here is the call graph for this function:

Member Function Documentation

◆ ActiveSortColumn()

int ui::qt::EventsTableModel::ActiveSortColumn ( ) const

Model column of the active sort, or -1 if there is none or its column is hidden.

Here is the caller graph for this function:

◆ ActiveSortOrder()

Qt::SortOrder ui::qt::EventsTableModel::ActiveSortOrder ( ) const
inline
Here is the caller graph for this function:

◆ AllColumnValues()

QSet< QString > ui::qt::EventsTableModel::AllColumnValues ( int  column) const

Distinct cell texts of column among all events, ignoring every filter.

Here is the caller graph for this function:

◆ AppendSortedRows()

void ui::qt::EventsTableModel::AppendSortedRows ( std::size_t  total)
private

Slots rows appended since the last full sort into the sorted list (O(k log k + n) instead of a full re-sort). Falls back to a full re-filter when the sorted list does not cover the previous events.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyEffectiveFilter()

void ui::qt::EventsTableModel::ApplyEffectiveFilter ( )
private

Rebuilds m_filteredIndices from the upstream filter + column filters (+ the active sort). Does not reset the model — callers do.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BaseFilterIsStale()

bool ui::qt::EventsTableModel::BaseFilterIsStale ( ) const
private

True if the upstream filter belongs to an older container generation or points past the container's end.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearColumnFilter()

void ui::qt::EventsTableModel::ClearColumnFilter ( int  column)
Here is the caller graph for this function:

◆ ClearColumnFilters()

void ui::qt::EventsTableModel::ClearColumnFilters ( )
Here is the caller graph for this function:

◆ ClearFilter()

void ui::qt::EventsTableModel::ClearFilter ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ columnCount()

int ui::qt::EventsTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override
Here is the caller graph for this function:

◆ ColumnFilterKey()

std::string ui::qt::EventsTableModel::ColumnFilterKey ( const std::string &  name,
bool  mergeSource 
)
staticprivate
Here is the caller graph for this function:

◆ ColumnFiltersChanged

void ui::qt::EventsTableModel::ColumnFiltersChanged ( )
signal
Here is the caller graph for this function:

◆ ColumnFilterValues()

QSet< QString > ui::qt::EventsTableModel::ColumnFilterValues ( int  column) const

Values of column's filter (empty set if none): the allowed values, or the excluded ones when IsColumnFilterExclusion().

Here is the caller graph for this function:

◆ ColumnWidths()

std::vector< int > ui::qt::EventsTableModel::ColumnWidths ( ) const
Here is the caller graph for this function:

◆ CompareSortKeys()

int ui::qt::EventsTableModel::CompareSortKeys ( const SortKey &  a,
const SortKey &  b 
)
staticprivate

Three-way ascending comparison of two keys (ties broken by event id).

◆ ComposeCellText()

QString ui::qt::EventsTableModel::ComposeCellText ( const db::LogEvent &  event,
const std::string &  columnName,
bool  mergeSource 
) const
private

mergeSource: the column is the dynamic multi-file "source" column (shows LogEvent::GetSource()). A configured data column that merely happens to be named "source" reads the event's own "source" field.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConfigIndexForColumn()

int ui::qt::EventsTableModel::ConfigIndexForColumn ( int  column) const

Index into Config::GetColumns() shown by model column; -1 for the dynamic source / original_id columns or an invalid column.

Here is the caller graph for this function:

◆ data()

QVariant ui::qt::EventsTableModel::data ( const QModelIndex &  index,
int  role 
) const
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DistinctColumnValues()

ColumnDistinctValues ui::qt::EventsTableModel::DistinctColumnValues ( int  column,
std::size_t  maxValues 
) const

Distinct cell texts of column among the rows that pass every filter except this column's own (so the list narrows as other columns are filtered, like Excel). At most maxValues values are returned.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndReset()

void ui::qt::EventsTableModel::EndReset ( )
private

Ends a model reset begun with beginResetModel(): repairs stale row state, then re-applies search highlighting. Row-set changes must be made after beginResetModel() so views can still map their selection to events.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBaseFilteredIndices()

const std::vector< unsigned long > * ui::qt::EventsTableModel::GetBaseFilteredIndices ( ) const
inline

The rows chosen by the rest of the application (SetFilteredIndices), before column filters and sorting; nullptr when no such filter is set.

Here is the caller graph for this function:

◆ GetFilteredIndices()

const std::vector< unsigned long > & ui::qt::EventsTableModel::GetFilteredIndices ( ) const
inline
Here is the caller graph for this function:

◆ GetSearchEngine()

const utils::SearchEngine & ui::qt::EventsTableModel::GetSearchEngine ( ) const
inline

◆ GetSortValue()

QVariant ui::qt::EventsTableModel::GetSortValue ( const db::LogEvent &  event,
const std::string &  columnName,
bool  mergeSource 
) const
private
Here is the call graph for this function:

◆ HasActiveColumnFilter()

bool ui::qt::EventsTableModel::HasActiveColumnFilter ( ) const

True if a column filter of a visible column restricts the rows (filters of hidden columns are kept but not applied).

Here is the caller graph for this function:

◆ HasAnyColumnFilter()

bool ui::qt::EventsTableModel::HasAnyColumnFilter ( ) const
inline

◆ HasColumnFilter()

bool ui::qt::EventsTableModel::HasColumnFilter ( int  column) const
Here is the caller graph for this function:

◆ HasStaleIndices()

bool ui::qt::EventsTableModel::HasStaleIndices ( ) const
private

True if the upstream filter or the effective row list is stale.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headerData()

QVariant ui::qt::EventsTableModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsColumnFilterExclusion()

bool ui::qt::EventsTableModel::IsColumnFilterExclusion ( int  column) const

True if column's filter hides the listed values instead of showing them.

Here is the caller graph for this function:

◆ IsFilteringActive()

bool ui::qt::EventsTableModel::IsFilteringActive ( ) const
inline

True if a filter is active — distinguishes "no filter" from "filter active, zero matches".

Here is the caller graph for this function:

◆ MakeSortKey()

EventsTableModel::SortKey ui::qt::EventsTableModel::MakeSortKey ( unsigned long  idx,
const std::string &  columnName,
bool  isMergeSource 
) const
private

◆ MatchCount()

int ui::qt::EventsTableModel::MatchCount ( ) const
inline
Here is the caller graph for this function:

◆ MatchedRows()

const std::vector< int > & ui::qt::EventsTableModel::MatchedRows ( ) const
inline
Here is the caller graph for this function:

◆ PassesColumnFilters()

bool ui::qt::EventsTableModel::PassesColumnFilters ( const db::LogEvent &  event,
const std::string *  skipKey 
) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PruneStaleColumnState()

EventsTableModel::PrunedColumnState ui::qt::EventsTableModel::PruneStaleColumnState ( )
private
Here is the caller graph for this function:

◆ RebuildSearchMatches()

void ui::qt::EventsTableModel::RebuildSearchMatches ( )
private
Here is the caller graph for this function:

◆ RebuildSearchMatchesAsync()

void ui::qt::EventsTableModel::RebuildSearchMatchesAsync ( )

Asynchronous search rebuild (doesn't block UI)

◆ RebuildVisibleColumns()

void ui::qt::EventsTableModel::RebuildVisibleColumns ( )
private
Here is the caller graph for this function:

◆ RefreshAll()

void ui::qt::EventsTableModel::RefreshAll ( )
Here is the call graph for this function:

◆ RefreshColumns()

void ui::qt::EventsTableModel::RefreshColumns ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResolveColumn()

bool ui::qt::EventsTableModel::ResolveColumn ( int  column,
std::string &  name,
bool &  mergeSource 
) const
private

Resolves a model column to its data-column name / merge-source flag.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResolveToActualIndex()

int ui::qt::EventsTableModel::ResolveToActualIndex ( int  row) const
Here is the caller graph for this function:

◆ rowCount()

int ui::qt::EventsTableModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RowFromActualIndex()

int ui::qt::EventsTableModel::RowFromActualIndex ( int  actualIndex) const
Here is the caller graph for this function:

◆ SearchMatchesChanged

void ui::qt::EventsTableModel::SearchMatchesChanged ( )
signal

Search matches were recomputed after the row set changed.

Here is the caller graph for this function:

◆ SetColumnFilter()

void ui::qt::EventsTableModel::SetColumnFilter ( int  column,
const QSet< QString > &  allowed 
)

Restricts column to allowed (an empty set matches nothing).

Here is the caller graph for this function:

◆ SetColumnFilterExcluding()

void ui::qt::EventsTableModel::SetColumnFilterExcluding ( int  column,
const QSet< QString > &  excluded 
)

Hides the excluded values of column and keeps every other value (used when the value list was too long to show completely).

Here is the caller graph for this function:

◆ SetFilteredIndices()

void ui::qt::EventsTableModel::SetFilteredIndices ( const std::vector< unsigned long > &  indices)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSearchMode()

void ui::qt::EventsTableModel::SetSearchMode ( utils::SearchMode  mode)

◆ SetSearchTerm()

void ui::qt::EventsTableModel::SetSearchTerm ( const QString &  term,
bool  caseSensitive 
)
Here is the caller graph for this function:

◆ ShouldShowOriginalIdColumn()

bool ui::qt::EventsTableModel::ShouldShowOriginalIdColumn ( ) const
private

◆ ShouldShowSourceColumn()

bool ui::qt::EventsTableModel::ShouldShowSourceColumn ( ) const
private

◆ sort()

void ui::qt::EventsTableModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
override
Here is the call graph for this function:

◆ SortBefore()

bool ui::qt::EventsTableModel::SortBefore ( unsigned long  a,
unsigned long  b 
) const
private

True if row a sorts before row b in the active sort.

◆ SortIndices()

void ui::qt::EventsTableModel::SortIndices ( std::vector< unsigned long > &  indices,
const std::string &  columnName,
bool  isMergeSource,
Qt::SortOrder  order 
) const
private
Here is the caller graph for this function:

◆ StoreColumnFilter()

void ui::qt::EventsTableModel::StoreColumnFilter ( int  column,
const QSet< QString > &  values,
bool  exclude 
)
private

◆ SyncWithContainer()

void ui::qt::EventsTableModel::SyncWithContainer ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateColors()

void ui::qt::EventsTableModel::UpdateColors ( )
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_baseFilterActive

bool ui::qt::EventsTableModel::m_baseFilterActive {false}
private

◆ m_baseFilteredIndices

std::vector<unsigned long> ui::qt::EventsTableModel::m_baseFilteredIndices
private

Rows chosen by the rest of the app.

◆ m_baseGeneration

std::uint64_t ui::qt::EventsTableModel::m_baseGeneration {0}
private

container generation the upstream filter was set for

◆ m_columnFilters

std::map<std::string, ColumnFilter> ui::qt::EventsTableModel::m_columnFilters
private

◆ m_config

const config::Config& ui::qt::EventsTableModel::m_config
private

◆ m_events

db::EventsContainer& ui::qt::EventsTableModel::m_events
private

◆ m_filteredIndices

std::vector<unsigned long> ui::qt::EventsTableModel::m_filteredIndices
private

Effective rows (upstream ∩ column filters, sorted if m_hasSort)

◆ m_filteringActive

bool ui::qt::EventsTableModel::m_filteringActive {false}
private

◆ m_fullSortedCount

std::size_t ui::qt::EventsTableModel::m_fullSortedCount {0}
private

Events covered by m_filteredIndices when it is the complete sorted list (no upstream or column filter); 0 when it is not such a list.

◆ m_hasSort

bool ui::qt::EventsTableModel::m_hasSort {false}
private

◆ m_hasSourceColumn

bool ui::qt::EventsTableModel::m_hasSourceColumn {false}
private

◆ m_indicesGeneration

std::uint64_t ui::qt::EventsTableModel::m_indicesGeneration {0}
private

container generation m_filteredIndices was built for

◆ m_matchedRows

std::vector<int> ui::qt::EventsTableModel::m_matchedRows
private

model row indices with at least one matching cell

◆ m_matchedRowSet

std::unordered_set<int> ui::qt::EventsTableModel::m_matchedRowSet
private

O(1) lookup used in data()

◆ m_reverseFilteredIndices

std::unordered_map<unsigned long, int> ui::qt::EventsTableModel::m_reverseFilteredIndices
private

◆ m_searchCaseSensitive

bool ui::qt::EventsTableModel::m_searchCaseSensitive {false}
private

◆ m_searchEngine

std::unique_ptr<utils::SearchEngine> ui::qt::EventsTableModel::m_searchEngine
private

◆ m_searchTerm

QString ui::qt::EventsTableModel::m_searchTerm
private

◆ m_sortMergeSource

bool ui::qt::EventsTableModel::m_sortMergeSource {false}
private

◆ m_sortName

std::string ui::qt::EventsTableModel::m_sortName
private

sort column by data name, so it survives column changes

◆ m_sortOrder

Qt::SortOrder ui::qt::EventsTableModel::m_sortOrder {Qt::AscendingOrder}
private

◆ m_visibleColumnIndices

std::vector<int> ui::qt::EventsTableModel::m_visibleColumnIndices
private

◆ m_visibleFilterKeys

std::set<std::string> ui::qt::EventsTableModel::m_visibleFilterKeys
private

Keys of the visible columns; only their filters apply.


The documentation for this class was generated from the following files: