From b484dae47f8b239aa428f1f69cba6ccc59589dd9 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 10 May 2012 17:23:50 +0300 Subject: [PATCH] Implemented removing selected items --- src/gui/UBFeaturesActionBar.cpp | 12 +++++++-- src/gui/UBFeaturesActionBar.h | 2 ++ src/gui/UBFeaturesWidget.cpp | 43 +++++++++++++++++++++++++++++++++ src/gui/UBFeaturesWidget.h | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 7d1f092d..60900c84 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -66,8 +66,8 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid mButtonGroup->addButton(mpRemoveFavoriteBtn); mButtonGroup->addButton(mpNewFolderBtn); // Connect signals & slots - connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); - /*connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); + /*connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); + connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); connect(mpSearchAction,SIGNAL(triggered()), this, SLOT(onActionSearch())); connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); connect(mpCloseAction, SIGNAL(triggered()), this, SLOT(onActionClose())); @@ -78,6 +78,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())); + connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); // Build the default toolbar mLayout->addWidget(mpFavoriteBtn); @@ -149,6 +150,8 @@ void UBFeaturesActionBar::setButtons() mpFavoriteBtn->hide(); mpSocialBtn->hide(); mSearchBar->show(); + mpDeleteBtn->show(); + mpDeleteBtn->setEnabled(true); //mpSearchBtn->show(); //mpDeleteBtn->hide(); mpCloseBtn->hide(); @@ -181,6 +184,11 @@ void UBFeaturesActionBar::onActionRemoveFavorite() emit removeElementsFromFavorite(); } +void UBFeaturesActionBar::onActionTrash() +{ + emit deleteSelectedElements(); +} + /* void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) { diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index deea070f..99664a6d 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -32,11 +32,13 @@ signals: void removeFromFavorite( const QMimeData &data ); void addElementsToFavorite(); void removeElementsFromFavorite(); + void deleteSelectedElements(); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); void onActionFavorite(); void onActionRemoveFavorite(); + void onActionTrash(); protected: //void dragMoveEvent(QDragMoveEvent *event); void dragEnterEvent( QDragEnterEvent *event ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index bc675a9f..8ee5e904 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -123,6 +123,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); connect( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); connect( mActionBar, SIGNAL( removeElementsFromFavorite() ), this, SLOT ( removeElementsFromFavorite() ) ); + connect( mActionBar, SIGNAL( deleteSelectedElements() ), this, SLOT( deleteSelectedElements() ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); @@ -278,6 +279,36 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) model->invalidate(); } +void UBFeaturesWidget::deleteSelectedElements() +{ + QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); + QList urls; + foreach ( QModelIndex sel, selected ) + { + UBFeature feature = sel.data( Qt::UserRole + 1 ).value(); + urls.append( feature.getFullPath() ); + } + + foreach (QUrl url, urls) + { + if ( controller->isTrash( url ) ) + { + controller->deleteItem( url ); + } + else + { + UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() ); + controller->removeFromFavorite( url ); + featuresModel->addItem( elem ); + featuresModel->deleteFavoriteItem( url.toString() ); + } + featuresModel->deleteItem( url.toString() ); + } + + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData ) { if ( !mimeData.hasUrls() ) @@ -902,6 +933,18 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path ) } } +void UBFeaturesModel::deleteItem( const QString &path ) +{ + for ( int i = 0; i < featuresList->size(); ++i ) + { + if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) ) + { + removeRow( i, QModelIndex() ); + return; + } + } +} + bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) { if ( row < 0 ) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 0fafc7d9..8ad8e8a3 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -103,6 +103,7 @@ private slots: void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray); void addElementsToFavorite(); void removeElementsFromFavorite(); + void deleteSelectedElements(); protected: bool eventFilter(QObject *target, QEvent *event); }; @@ -200,6 +201,7 @@ public: void addItem( const UBFeature &item ); void deleteFavoriteItem( const QString &path ); + void deleteItem( const QString &path ); QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const;