From 3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 18 Mar 2012 01:47:21 +0100 Subject: Fix some severe braindamage It started as a buxfix session, but the more I dug into some ancient code, the more I had to change. Well, first and foremost, this fixes a crash in PicturesWidget. Trying to display the mappings of the selected picture in a different color never was a good idea. Show them in the statusbar instead. While looking at the statusBar code, make PictureWidget emit signals to show the total size and number of selected items. Then I noticed some really, really braindamaged connection madness in the Shemov constructor. Instead of doing all the work in SheMov itself, have the widgets emit signals. This should have been several commits, but one lead to another... --- filestreewidget.cpp | 59 +++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'filestreewidget.cpp') diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 1a17be5..6222d99 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -54,8 +54,7 @@ FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSi mView->setModel(mProxy); mView->setSortingEnabled(true); QItemSelectionModel *selModel = mView->selectionModel(); - connect(selModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(fileSelectionChanged(QModelIndex,QModelIndex))); - connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection))); + connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged())); connect(mView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(itemDoubleClicked(QModelIndex))); //layout @@ -70,7 +69,7 @@ FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSi void FilesTreeWidget::resetSize(){ mSelectedSize = 0; - emit sizeChanged(mSelectedSize); + emit selectedSize(mSelectedSize); } void FilesTreeWidget::moveToBurn(){ @@ -287,23 +286,27 @@ void FilesTreeWidget::suggest(){ mView->scrollTo(last, QAbstractItemView::PositionAtCenter); } -void FilesTreeWidget::fileSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous){ - Q_UNUSED(previous); - int seriesPartId = current.data(FilesTreeModel::SeriesPartIdRole).toInt(); - int seriesId = mSeriesModel->seriesIdByPartId(seriesPartId); - int filePart = current.data(FilesTreeModel::PartNoRole).toInt(); - QModelIndex seriesIdx = mSeriesModel->findValue(seriesId, QModelIndex(), SeriesTreeModel::SeriesId); - if(seriesIdx.isValid()){ - QModelIndex seriesPartIdx = mSeriesModel->findValue(seriesPartId, seriesIdx, SeriesTreeModel::SeriesPartId); - QString seriesNumber = QString::number(seriesPartIdx.data(SeriesTreeModel::SeriesPartRole).toInt()); - QString msg; - if(filePart > 0){ - msg = QString(tr("%1 %2 (%3)")).arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber).arg(filePart); - }else{ - msg = QString(tr("%1 %2")).arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber); - } - emit statusMessage(msg); - } +void FilesTreeWidget::fileSelectionChanged(){ + QModelIndexList selected = mView->selectionModel()->selectedRows(); + qint64 selSize = 0; + QStringList selectedSeries; + foreach(QModelIndex idx, selected){ + selSize += idx.data(FilesTreeModel::SizeRole).toLongLong(); + int seriesPartId = idx.data(FilesTreeModel::SeriesPartIdRole).toInt(); + int seriesId = mSeriesModel->seriesIdByPartId(seriesPartId); + QModelIndex seriesIdx = mSeriesModel->findValue(seriesId, QModelIndex(), SeriesTreeModel::SeriesId); + if(seriesIdx.isValid()){ + QModelIndex seriesPartIdx = mSeriesModel->findValue(seriesPartId, seriesIdx, SeriesTreeModel::SeriesPartId); + QString seriesNumber = QString::number(seriesPartIdx.data(SeriesTreeModel::SeriesPartRole).toInt()); + QString seriesString = QString("%1 %2").arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber); + if(!selectedSeries.contains(seriesString)){ + selectedSeries << seriesString; + } + } + } + emit selectedSize(selSize); + emit numSelected(selected.size()); + emit statusMessage(QString(tr("Series: %1")).arg(selectedSeries.join(","))); } void FilesTreeWidget::itemDoubleClicked(const QModelIndex &index){ @@ -334,22 +337,6 @@ void FilesTreeWidget::itemDoubleClicked(const QModelIndex &index){ } } -void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){ - QModelIndexList sel = selected.indexes(); - QModelIndexList desel = deselected.indexes(); - foreach(QModelIndex i, sel){ - if(i.column() == 0){ - mSelectedSize += i.data(FilesTreeModel::SizeRole).toLongLong(); - } - } - foreach(QModelIndex i, desel){ - if(i.column() == 0){ - mSelectedSize -= i.data(FilesTreeModel::SizeRole).toLongLong(); - } - } - emit sizeChanged(mSelectedSize); -} - FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent), mHoverWin(new HoverWindow), mHoverPics(false){ setAttribute(Qt::WA_Hover); } -- cgit v1.2.3-70-g09d2