Skip to content

Commit

Permalink
Fix Crash resizing a column that doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishwaldo committed Jun 8, 2020
1 parent 6eb844a commit 18f15f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
16 changes: 5 additions & 11 deletions ozwadmin-main/valuetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,30 @@ ValueTable::ValueTable(QTOZW_ValueIds::ValueIdGenres genre, QWidget *parent) :
this->setSelectionMode(QAbstractItemView::SingleSelection);
this->setSortingEnabled(true);
this->horizontalHeader()->setSectionsMovable(true);
this->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
}

void ValueTable::setModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel)
{
this->m_proxyModel->setSourceModel(model);
this->m_proxyModel->setSelectionModel(selectionModel);
connect(this->m_proxyModel, &QAbstractItemModel::rowsInserted, this, &ValueTable::resizeContents);
connect(this->m_proxyModel, &QAbstractItemModel::rowsRemoved, this, &ValueTable::resizeContents);

//connect(selectionModel, &QItemSelectionModel::currentRowChanged, this, &ValueTable::logChanges);
QTableView::setModel(this->m_proxyModel);
/* move the Instance Column to the first entry */
this->horizontalHeader()->moveSection(QTOZW_ValueIds::ValueIdColumns::Instance, 0);

for (int i = 0; i <= QTOZW_ValueIds::ValueIdColumns::ValueIdCount; i++) {
switch (i) {
case QTOZW_ValueIds::ValueIdColumns::Label:
case QTOZW_ValueIds::ValueIdColumns::Value:
case QTOZW_ValueIds::ValueIdColumns::Instance:
case QTOZW_ValueIds::ValueIdColumns::Help:
break;
this->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
break;
default:
this->horizontalHeader()->hideSection(i);
}
}
QTimer::singleShot(500, this, &ValueTable::resizeContents);
}

void ValueTable::resizeContents() {
this->resizeColumnsToContents();
}

void forEach(QAbstractItemModel* model, QModelIndex parent = QModelIndex()) {
Expand All @@ -59,8 +55,6 @@ void forEach(QAbstractItemModel* model, QModelIndex parent = QModelIndex()) {
}
}



void ValueTable::logChanges(const QModelIndex &current, const QModelIndex &previous)
{
qCDebug(ozwadmin) << "SelectionChanged UnFiltered Rows:" << this->m_proxyModel->sourceModel()->rowCount();
Expand Down
1 change: 0 additions & 1 deletion ozwadmin-main/valuetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ValueTable : public QTableView
public slots:

private slots:
void resizeContents();
void logChanges(const QModelIndex &current, const QModelIndex &previous);
private:
QTOZW_proxyValueModel *m_proxyModel;
Expand Down

0 comments on commit 18f15f4

Please sign in to comment.