From 4150279b9fb146089106ef4a36e8db2cea914951 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Tue, 8 May 2012 14:41:04 +0300 Subject: [PATCH] Implemented removing selected items from favorite --- src/gui/UBFeaturesActionBar.cpp | 6 ++++++ src/gui/UBFeaturesActionBar.h | 2 ++ src/gui/UBFeaturesWidget.cpp | 27 ++++++++++++++++++++++++--- src/gui/UBFeaturesWidget.h | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 8311bfc9..7d1f092d 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -77,6 +77,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); + connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); // Build the default toolbar mLayout->addWidget(mpFavoriteBtn); @@ -175,6 +176,11 @@ void UBFeaturesActionBar::onActionFavorite() emit addElementsToFavorite(); } +void UBFeaturesActionBar::onActionRemoveFavorite() +{ + emit removeElementsFromFavorite(); +} + /* void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) { diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 7aec99a9..deea070f 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -31,10 +31,12 @@ signals: void addToFavorite( const QMimeData &data ); void removeFromFavorite( const QMimeData &data ); void addElementsToFavorite(); + void removeElementsFromFavorite(); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); void onActionFavorite(); + void onActionRemoveFavorite(); protected: //void dragMoveEvent(QDragMoveEvent *event); void dragEnterEvent( QDragEnterEvent *event ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 7a71b555..a8380a69 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -121,7 +121,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) ); connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) ); connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); - connect ( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); + connect( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); + connect( mActionBar, SIGNAL( removeElementsFromFavorite() ), this, SLOT ( removeElementsFromFavorite() ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); @@ -348,6 +349,25 @@ void UBFeaturesWidget::addElementsToFavorite() model->invalidate(); } +void UBFeaturesWidget::removeElementsFromFavorite() +{ + QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); + //qSort( selected.begin(), selected.end(), qGreater() ); + QList items; + for ( int i = 0; i < selected.size(); ++i ) + { + UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); + items.append( feature.getFullPath() ); + } + foreach ( QUrl url, items ) + { + controller->removeFromFavorite( url ); + featuresModel->deleteFavoriteItem( url.toString() ); + } + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -435,7 +455,7 @@ void UBFeaturesListView::dropEvent( QDropEvent *event ) { event->setDropAction( Qt::MoveAction ); } - QListView::dropEvent( event ); + QListView::dropEvent( event ); } @@ -854,7 +874,7 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path ) { for ( int i = 0; i < featuresList->size(); ++i ) { - if ( !QString::compare( featuresList->at(i).getUrl(), path, Qt::CaseInsensitive ) && + if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) && !QString::compare( featuresList->at(i).getVirtualPath(), "/root/favorites", Qt::CaseInsensitive ) ) { removeRow( i, QModelIndex() ); @@ -889,6 +909,7 @@ bool UBFeaturesModel::removeRow( int row, const QModelIndex & parent ) return true; } + Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const { Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 85aaebbd..6050fc33 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -102,6 +102,7 @@ private slots: void onDisplayMetadata( QMap ); void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray); void addElementsToFavorite(); + void removeElementsFromFavorite(); protected: bool eventFilter(QObject *target, QEvent *event); }; @@ -209,6 +210,8 @@ public: bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + //bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); + //bool insertRow(int row, const QModelIndex &parent = QModelIndex()); Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }