diff options
-rw-r--r-- | AutoSizingList.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/AutoSizingList.cpp b/AutoSizingList.cpp index c20794d..cb99151 100644 --- a/AutoSizingList.cpp +++ b/AutoSizingList.cpp @@ -27,22 +27,23 @@ AutoSizingList::AutoSizingList(QWidget *parent) } void AutoSizingList::rowChange() { + CollectionFilter *filter = qobject_cast<CollectionFilter*>(model()); + if(filter && filter->rowCount() == 0) + return; setUpdatesEnabled(false); header()->setStretchLastSection(false); - QAbstractItemModel *abstractModel = model(); - CollectionModel *model = 0; - CollectionFilter *filter = qobject_cast<CollectionFilter*>(abstractModel); + CollectionModel *collectionModel = 0; if(filter) - model = qobject_cast<CollectionModel*>(filter->sourceModel()); - if(model) - model->setFakeBoldState(true); + collectionModel = qobject_cast<CollectionModel*>(filter->sourceModel()); + if(collectionModel) + collectionModel->setFakeBoldState(true); double suggestedWidth0 = qMin(sizeHintForColumn(0), 70); setColumnWidth(0, suggestedWidth0); double suggestedWidth1 = sizeHintForColumn(1); double suggestedWidth2 = sizeHintForColumn(2); double suggestedWidth3 = sizeHintForColumn(3); - if(model) - model->setFakeBoldState(false); + if(collectionModel) + collectionModel->setFakeBoldState(false); header()->setStretchLastSection(true); double suggestedWidthTotal = suggestedWidth0 + suggestedWidth1 + suggestedWidth2 + suggestedWidth3; @@ -80,12 +81,18 @@ void AutoSizingList::rowChange() void AutoSizingList::fixColumnSizes() { setUpdatesEnabled(false); - if(m_suggestedRatio1 + m_suggestedRatio2 + m_suggestedRatio3) { + if(m_suggestedRatio1 + m_suggestedRatio2 + m_suggestedRatio3 != 0) { int width = viewport()->width() - 40; //HACK: Why not 0? setColumnWidth(1, m_suggestedRatio1 * width); setColumnWidth(2, m_suggestedRatio2 * width); setColumnWidth(3, m_suggestedRatio3 * width); } + CollectionFilter *filter = qobject_cast<CollectionFilter*>(model()); + if(filter) { + QModelIndex index = filter->currentItem(); + if(index.isValid()) + scrollTo(filter->mapFromSource(index), QAbstractItemView::PositionAtCenter); + } setUpdatesEnabled(true); } void AutoSizingList::resizeEvent(QResizeEvent *event) |