summaryrefslogtreecommitdiffstats
path: root/filestreewidget.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-03-18 01:47:21 +0100
committerArno <am@disconnect.de>2012-03-18 01:47:21 +0100
commit3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543 (patch)
treeae756b5b493aacb6c486a13b3e4fd0d9a0e4d801 /filestreewidget.cpp
parent1e14ae6748f271265dd719ac0766a2da3501a21f (diff)
downloadSheMov-3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543.tar.gz
SheMov-3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543.tar.bz2
SheMov-3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543.zip
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...
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r--filestreewidget.cpp59
1 files changed, 23 insertions, 36 deletions
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 &current, 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);
}