diff options
author | Arno <am@disconnect.de> | 2012-03-18 01:47:21 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-03-18 01:47:21 +0100 |
commit | 3e784fed0148c4ec24aa8b2b8ca53f2d9d9bc543 (patch) | |
tree | ae756b5b493aacb6c486a13b3e4fd0d9a0e4d801 | |
parent | 1e14ae6748f271265dd719ac0766a2da3501a21f (diff) | |
download | SheMov-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...
-rw-r--r-- | filestreewidget.cpp | 59 | ||||
-rw-r--r-- | filestreewidget.h | 6 | ||||
-rw-r--r-- | filesystemwidget.cpp | 1 | ||||
-rw-r--r-- | fileview.cpp | 12 | ||||
-rw-r--r-- | fileview.h | 7 | ||||
-rw-r--r-- | mappingtreemodel.cpp | 22 | ||||
-rw-r--r-- | mappingtreemodel.h | 1 | ||||
-rw-r--r-- | pictureswidget.cpp | 31 | ||||
-rw-r--r-- | pictureswidget.h | 8 | ||||
-rw-r--r-- | shemov.cpp | 37 | ||||
-rw-r--r-- | shemov.h | 2 |
11 files changed, 82 insertions, 104 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 ¤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); } diff --git a/filestreewidget.h b/filestreewidget.h index 940d9de..54393dd 100644 --- a/filestreewidget.h +++ b/filestreewidget.h @@ -41,12 +41,12 @@ class FilesTreeWidget : public QWidget { void suggest(); private slots: - void fileSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); - void fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + void fileSelectionChanged(); void itemDoubleClicked(const QModelIndex &index); signals: - void sizeChanged(qint64); + void selectedSize(qint64); + void numSelected(int); void statusMessage(QString); private: diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 38edbab..e86db07 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -70,6 +70,7 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent), mClipboar mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); mFileView->setEditTriggers(QAbstractItemView::NoEditTriggers); mFileView->setAlternatingRowColors(true); + connect(mFileView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), mFileView, SLOT(selectedFilesChanged())); mPicViewer = SmGlobals::instance()->pictureViewer(); diff --git a/fileview.cpp b/fileview.cpp index f0169de..bd0492f 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -198,6 +198,18 @@ bool FileView::event(QEvent *e){ return QTreeView::event(e); } +void FileView::selectedFilesChanged(){ + QModelIndexList selected = selectionModel()->selectedRows(); + emit numSelected(selected.size()); + qint64 selSize = 0; + foreach(QModelIndex i, selected){ + QString path = i.data(QFileSystemModel::FilePathRole).toString(); + QFileInfo fi(path); + selSize += fi.size(); + } + emit selectedSize(selSize); +} + bool FileView::exitHover(bool exitVal){ mHoverWin->setVisible(false); mCurHover = QModelIndex(); @@ -31,6 +31,8 @@ class FileView : public QTreeView { void enterPressed(const QModelIndex &); void statusbarMessage(const QString &); void editorClosed(const QModelIndex &idx); + void numSelected(int); + void selectedSize(qint64); public slots: void markFiles(); @@ -46,7 +48,10 @@ class FileView : public QTreeView { virtual void keyPressEvent(QKeyEvent *e); virtual void resizeEvent(QResizeEvent *e); virtual bool event(QEvent *event); - + + private slots: + void selectedFilesChanged(); + private: enum HoverFileType { Dir, Movie, Image, None }; bool exitHover(bool exitVal = true); diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index 5ab6068..9b849d9 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -291,28 +291,6 @@ MappingData MappingTreeModel::mappingDataFromId(int mappingId) const{ return retval; } -void MappingTreeModel::setSelectedMappings(const QList<int> &mappingIds){ - //we can't change the list we're iterating over... that would wreak havoc - QList<SmTreeItem*> iterateList = mSelectedMappings; - foreach(SmTreeItem *item, iterateList){ - mSelectedMappings.removeAll(item); - QModelIndex idxStart = createIndex(item->parent()->row(), 0, item); - QModelIndex idxEnd = createIndex(item->parent()->row(), NumFields - 1, item); - emit dataChanged(idxStart, idxEnd); - } - mSelectedMappings.clear(); - foreach(int id, mappingIds){ - QModelIndex idx = findRecursive(id, Id); - if(idx.isValid()){ - SmTreeItem *item = static_cast<SmTreeItem*>(idx.internalPointer()); - mSelectedMappings << item; - QModelIndex idxStart = createIndex(item->parent()->row(), 0, item); - QModelIndex idxEnd = createIndex(item->parent()->row(), NumFields - 1, item); - emit dataChanged(idxStart, idxEnd); - } - } -} - QStringList MappingTreeModel::paths() const{ return getPathsRecursive(root()); } diff --git a/mappingtreemodel.h b/mappingtreemodel.h index 50843ba..7a3b5fe 100644 --- a/mappingtreemodel.h +++ b/mappingtreemodel.h @@ -44,7 +44,6 @@ class MappingTreeModel : public SmTreeModel { bool deleteChild(const QModelIndex &idx); int childCount(const QModelIndex &idx) const; MappingData mappingDataFromId(int mappingId) const; - void setSelectedMappings(const QList<int> &mappingData); QStringList paths() const; const QString &forbidden() const { return mForbidden; } diff --git a/pictureswidget.cpp b/pictureswidget.cpp index b420309..95e8a60 100644 --- a/pictureswidget.cpp +++ b/pictureswidget.cpp @@ -35,7 +35,6 @@ PicturesWidget::PicturesWidget(QWidget *parent) : QWidget(parent), mWindowTitleB connect(mMappingTree, SIGNAL(mappingChanged(int)), mPictureView, SLOT(mappingChanged(int))); //change window title when mapping selection changes connect(mMappingTree, SIGNAL(mappingChanged(int)), this, SLOT(constructWindowTitle())); - connect(mPictureView, SIGNAL(newFileMappigs()), this, SLOT(setMappingColors())); connect(mPictureView, SIGNAL(editPicsMappings()), this, SLOT(editMappings())); connect(mPictureView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(showInPicViewer(QModelIndex))); splitter->addWidget(mMappingTree); @@ -58,11 +57,6 @@ void PicturesWidget::showPicViewer(bool toggled){ mPicViewer->setVisible(toggled); } -void PicturesWidget::setMappingColors(){ - MappingTreeModel *mtm = static_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree")); - mtm->setSelectedMappings(mPictureView->fileMappings()); -} - void PicturesWidget::editMappings(){ QList<int> currentMappings = mPictureView->fileMappings(); mEditDialog->editWidget()->setMappings(currentMappings); @@ -106,12 +100,13 @@ void PicturesWidget::showInPicViewer(const QModelIndex &idx){ } PictureView::PictureView(QWidget *parent) : QTreeView(parent) { - //setup model + //setup models mModel = new PicFilesModel(QStringList() << tr("Filename") << tr("SizeNum") << tr("Format") << tr("Full Path") << tr("Id") << tr("Added") << tr("Md5Sum") << tr("Size"), this); mProxy = new QSortFilterProxyModel(this); mProxy->setSourceModel(mModel); setModel(mProxy); - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(setFileMappings())); + connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectedFilesChanged())); + mMappingTreeModel = static_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree")); //read settings QSettings s; @@ -237,17 +232,33 @@ void PictureView::contextMenuEvent(QContextMenuEvent *e){ ctxMenu.exec(e->globalPos()); } -void PictureView::setFileMappings(){ +void PictureView::selectedFilesChanged(){ QModelIndexList sel = selectionModel()->selectedRows(); if(sel.isEmpty()){ return; } + //file mappings QList<QVariant> fileIds; + qint64 selSize = 0; foreach(QModelIndex i, sel){ fileIds << i.data(PicFilesModel::IdRole); + selSize += i.data(PicFilesModel::SizeRole).toInt(); } mFilesMappings = mModel->mappingIds(fileIds); - emit newFileMappigs(); + QStringList mappings; + foreach(int m, mFilesMappings){ + MappingData mapping = mMappingTreeModel->mappingDataFromId(m); + if(!mappings.contains(mapping.name)){ + mappings << mapping.name; + } + } + qSort(mappings); + QString mappingMsg = QString(tr("Mappings: %1")).arg(mappings.join(",")); + emit newMappings(mappingMsg); + + //selected items + emit numSelected(sel.size()); + emit selectedSize(selSize); } PicFilesModel::PicFilesModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent) { diff --git a/pictureswidget.h b/pictureswidget.h index cdc40b5..a8463a4 100644 --- a/pictureswidget.h +++ b/pictureswidget.h @@ -41,7 +41,6 @@ class PicturesWidget : public QWidget { void showPicViewer(bool toggled); private slots: - void setMappingColors(); void editMappings(); void constructWindowTitle(); void showInPicViewer(const QModelIndex &idx); @@ -82,10 +81,12 @@ class PictureView : public QTreeView { virtual void contextMenuEvent(QContextMenuEvent *e); private slots: - void setFileMappings(); + void selectedFilesChanged(); signals: - void newFileMappigs(); + void newMappings(QString); + void numSelected(int); + void selectedSize(qint64); void editPicsMappings(); private: @@ -96,6 +97,7 @@ class PictureView : public QTreeView { int mCursorOffset; QList<int> mFilesMappings; PictureViewer2 *mPV; + MappingTreeModel *mMappingTreeModel; }; class PicFilesModel : public SmTreeModel { @@ -76,16 +76,19 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla mATree = new ArchiveTreeView; mTab->addTab(mATree, "Archive"); connect(mATree->filesWidget(), SIGNAL(statusMessage(QString)), this, SLOT(statusbarMessage(QString))); - connect(mATree->filesWidget(), SIGNAL(sizeChanged(qint64)), this, SLOT(setSize(qint64))); connect(mATree, SIGNAL(needWindowTitleChange(QString)), this, SLOT(setWindowTitle(QString))); - connect(mATree->filesWidget()->filesTree()->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(updateSelectionCount(const QItemSelection &, const QItemSelection &))); - connect(mATree->seriesWidget()->seriesTree()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateSelectionCount(QItemSelection,QItemSelection))); + connect(mATree->filesWidget(), SIGNAL(numSelected(int)), this, SLOT(updateSelectedCount(int))); + connect(mATree->filesWidget(), SIGNAL(selectedSize(qint64)), this, SLOT(setSize(qint64))); + connect(mATree->filesWidget(), SIGNAL(statusMessage(QString)), this, SLOT(statusbarMessage(QString))); connect(this, SIGNAL(configChanged()), mATree, SLOT(readSettings())); //pictures mPicWidget = new PicturesWidget; mTab->addTab(mPicWidget, tr("Pictures")); connect(mPicWidget, SIGNAL(needWindowTitleChange(QString)), this, SLOT(setWindowTitle(QString))); + connect(mPicWidget->picView(), SIGNAL(newMappings(QString)), this, SLOT(statusbarMessage(QString))); + connect(mPicWidget->picView(), SIGNAL(numSelected(int)), this, SLOT(updateSelectedCount(int))); + connect(mPicWidget->picView(), SIGNAL(selectedSize(qint64)), this, SLOT(setSize(qint64))); //newmoviewizard + dbanalyzer mNewMovieWizard = new NewMovieWizard(this); @@ -103,7 +106,8 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla createToolBar(); setFsFree(); - connect(mFSWidget->fileView()->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(updateSelectionCount(const QItemSelection &, const QItemSelection &))); + connect(mFSWidget->fileView(), SIGNAL(selectedSize(qint64)), this, SLOT(setSize(qint64))); + connect(mFSWidget->fileView(), SIGNAL(numSelected(int)), this, SLOT(updateSelectedCount(int))); connect(mFSWidget, SIGNAL(windowTitle(QString)), this, SLOT(setWindowTitle(QString))); connect(mFSWidget->fileView(), SIGNAL(statusbarMessage(const QString &)), this, SLOT(statusbarMessage(const QString &))); connect(mFSWidget, SIGNAL(statusbarMessage(const QString &)), this, SLOT(statusbarMessage(const QString &))); @@ -142,28 +146,8 @@ void SheMov::closeEvent(QCloseEvent *event){ event->accept(); } -void SheMov::updateSelectionCount(const QItemSelection & /* sel */, const QItemSelection & /* prev */){ - QLocale l; - switch (mTab->currentIndex()) { - case 0: { - int selCount = mFSWidget->fileView()->selectionModel()->selectedRows().count(); - mSelectedItems->setText(QString::number(selCount)); - qint64 selSize(0); - foreach(QModelIndex idx, mFSWidget->fileView()->selectionModel()->selectedRows()){ - QModelIndex real = mFSWidget->fileProxy()->mapToSource(idx); - if(real.isValid()){ - QFileInfo fi = mFSWidget->dirModel()->fileInfo(real); - selSize += fi.size(); - } - } - mSelectedSize->setText(QString(tr("<span style=\"color:#000000\">%1</span>")).arg(l.toString((selSize)))); - break; - } - case 1: { - int selCount = mATree->filesWidget()->filesTree()->selectionModel()->selectedRows().count(); - mSelectedItems->setText(QString::number(selCount)); - } - } +void SheMov::updateSelectedCount(int count){ + mSelectedItems->setText(QString::number(count)); } void SheMov::statusbarMessage(const QString &message){ @@ -196,7 +180,6 @@ void SheMov::tabChanged(int newTab){ mShowTreeGroup->setEnabled(newTab == 1); mPicActionGroup->setEnabled(newTab == 2); mFilterFavoritesA->setEnabled(newTab == 1); - updateSelectionCount(QItemSelection(), QItemSelection()); } void SheMov::setFsFree(){ @@ -36,7 +36,7 @@ class SheMov : public QMainWindow { virtual void closeEvent(QCloseEvent *event); private slots: - void updateSelectionCount(const QItemSelection &sel, const QItemSelection &prev); + void updateSelectedCount(int count); void statusbarMessage(const QString &message); void setTemplate(const QString &newTemplate); void configure(); |