Skip to content

Commit

Permalink
Speed up control flow when initializing track table headers
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 19, 2024
1 parent 77f9632 commit 6cf045a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
31 changes: 11 additions & 20 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,21 @@ void BaseTrackTableModel::initTableColumnsAndHeaderProperties(

// Reset the column headers.
m_columnHeaders.clear();
m_columnHeaders.resize(tableColumns.size());

// Init the header properties of selected/visible columns.
initHeaderProperties();
}
VERIFY_OR_DEBUG_ASSERT(tableColumns.size() > 0) {
return;
}

m_columnHeaders.resize(tableColumns.size());

void BaseTrackTableModel::initHeaderProperties() {
// Init the mapping of all columns, even for internal columns that are
// hidden/invisible. Otherwise mapColumn() would not return a valid result
// for those columns.
for (int column = 0; column < ColumnCache::NUM_COLUMNS; ++column) {
setHeaderProperties(static_cast<ColumnCache::Column>(column));
}

emit headerDataChanged(Qt::Horizontal, 0, tableColumns.size() - 1);
}

void BaseTrackTableModel::setHeaderProperties(ColumnCache::Column column) {
Expand All @@ -149,21 +151,10 @@ void BaseTrackTableModel::setHeaderProperties(ColumnCache::Column column) {
return;
}
m_columnHeaders[section].column = column;
setHeaderData(
section,
Qt::Horizontal,
m_columnCache.columnName(column),
TrackModel::kHeaderNameRole);
setHeaderData(
section,
Qt::Horizontal,
m_columnCache.columnTitle(column),
Qt::DisplayRole);
setHeaderData(
section,
Qt::Horizontal,
m_columnCache.columnDefaultWidth(column),
TrackModel::kHeaderWidthRole);
m_columnHeaders[section].header[TrackModel::kHeaderNameRole] = m_columnCache.columnName(column);
m_columnHeaders[section].header[Qt::DisplayRole] = m_columnCache.columnTitle(column);
m_columnHeaders[section].header[TrackModel::kHeaderWidthRole] =
m_columnCache.columnDefaultWidth(column);
}

bool BaseTrackTableModel::setHeaderData(
Expand Down
2 changes: 0 additions & 2 deletions src/library/basetracktablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
// Overridable functions
///////////////////////////////////////////////////////

virtual void initHeaderProperties();

// Use this if you want a model that is read-only.
virtual Qt::ItemFlags readOnlyFlags(
const QModelIndex& index) const;
Expand Down
4 changes: 2 additions & 2 deletions src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/// which display track lists.
class TrackModel {
public:
static const int kHeaderWidthRole = Qt::UserRole + 0;
static const int kHeaderNameRole = Qt::UserRole + 1;
static constexpr int kHeaderWidthRole = Qt::UserRole + 0;
static constexpr int kHeaderNameRole = Qt::UserRole + 1;
// This role is used for data export like in CSV files
static constexpr int kDataExportRole = Qt::UserRole + 2;

Expand Down

0 comments on commit 6cf045a

Please sign in to comment.