Commit 17c1d0fd authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Remove deprecated Akonadi::ItemView & Akonadi::CollectionView

No more users known
parent 832c36a3
Pipeline #89641 passed with stage
in 13 minutes and 51 seconds
......@@ -34,7 +34,6 @@ target_sources(KF5AkonadiWidgets PRIVATE
collectionpropertiespage.cpp
collectionrequester.cpp
collectionstatisticsdelegate.cpp
collectionview.cpp
conflictresolvedialog.cpp
controlgui.cpp
dragdropmanager.cpp
......@@ -42,7 +41,6 @@ target_sources(KF5AkonadiWidgets PRIVATE
entitytreeview.cpp
erroroverlay.cpp
etmviewstatesaver.cpp
itemview.cpp
manageaccountwidget.cpp
progressspinnerdelegate.cpp
recentcollectionaction.cpp
......@@ -96,12 +94,10 @@ ecm_generate_headers(AkonadiWidgets_CC_HEADERS
CollectionMaintenancePage
CollectionRequester
CollectionStatisticsDelegate
CollectionView
ControlGui
EntityListView
EntityTreeView
ETMViewStateSaver
ItemView
ManageAccountWidget
StandardActionManager
SubscriptionDialog
......
/*
SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "collectionview.h"
#include "akonadiwidgets_debug.h"
#include "collection.h"
#include "controlgui.h"
#include "entitytreemodel.h"
#include <KLocalizedString>
#include <KXMLGUIFactory>
#include <kxmlguiwindow.h>
#include <QAction>
#include <QApplication>
#include <QDragMoveEvent>
#include <QHeaderView>
#include <QMenu>
#include <QMimeData>
#include <QTimer>
#include <QUrl>
#include <QUrlQuery>
using namespace Akonadi;
/**
* @internal
*/
class Q_DECL_HIDDEN CollectionView::Private
{
public:
explicit Private(CollectionView *parent)
: mParent(parent)
{
}
void init();
void dragExpand();
void itemClicked(const QModelIndex &index);
void itemCurrentChanged(const QModelIndex &index);
bool hasParent(const QModelIndex &idx, Collection::Id parentId) const;
CollectionView *const mParent;
QModelIndex dragOverIndex;
QTimer dragExpandTimer;
KXMLGUIClient *xmlGuiClient = nullptr;
};
void CollectionView::Private::init()
{
mParent->header()->setSectionsClickable(true);
mParent->header()->setStretchLastSection(false);
mParent->setSortingEnabled(true);
mParent->sortByColumn(0, Qt::AscendingOrder);
mParent->setEditTriggers(QAbstractItemView::EditKeyPressed);
mParent->setAcceptDrops(true);
mParent->setDropIndicatorShown(true);
mParent->setDragDropMode(DragDrop);
mParent->setDragEnabled(true);
dragExpandTimer.setSingleShot(true);
mParent->connect(&dragExpandTimer, &QTimer::timeout, mParent, [this]() {
dragExpand();
});
mParent->connect(mParent, &QAbstractItemView::clicked, mParent, [this](const QModelIndex &mi) {
itemClicked(mi);
});
ControlGui::widgetNeedsAkonadi(mParent);
}
bool CollectionView::Private::hasParent(const QModelIndex &idx, Collection::Id parentId) const
{
QModelIndex idx2 = idx;
while (idx2.isValid()) {
if (mParent->model()->data(idx2, EntityTreeModel::CollectionIdRole).toLongLong() == parentId) {
return true;
}
idx2 = idx2.parent();
}
return false;
}
void CollectionView::Private::dragExpand()
{
mParent->setExpanded(dragOverIndex, true);
dragOverIndex = QModelIndex();
}
void CollectionView::Private::itemClicked(const QModelIndex &index)
{
if (!index.isValid()) {
return;
}
const auto collection = index.model()->data(index, EntityTreeModel::CollectionRole).value<Collection>();
if (!collection.isValid()) {
return;
}
Q_EMIT mParent->clicked(collection);
}
void CollectionView::Private::itemCurrentChanged(const QModelIndex &index)
{
if (!index.isValid()) {
return;
}
const auto collection = index.model()->data(index, EntityTreeModel::CollectionRole).value<Collection>();
if (!collection.isValid()) {
return;
}
Q_EMIT mParent->currentChanged(collection);
}
CollectionView::CollectionView(QWidget *parent)
: QTreeView(parent)
, d(new Private(this))
{
d->init();
}
CollectionView::CollectionView(KXMLGUIClient *xmlGuiClient, QWidget *parent)
: QTreeView(parent)
, d(new Private(this))
{
d->xmlGuiClient = xmlGuiClient;
d->init();
}
CollectionView::~CollectionView() = default;
void CollectionView::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
header()->setStretchLastSection(true);
connect(selectionModel(), &QItemSelectionModel::currentChanged, this, [this](const QModelIndex &mi) {
d->itemCurrentChanged(mi);
});
}
void CollectionView::dragMoveEvent(QDragMoveEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (d->dragOverIndex != index) {
d->dragExpandTimer.stop();
if (index.isValid() && !isExpanded(index) && itemsExpandable()) {
d->dragExpandTimer.start(QApplication::startDragTime());
d->dragOverIndex = index;
}
}
// Check if the collection under the cursor accepts this data type
const QStringList supportedContentTypes = model()->data(index, EntityTreeModel::CollectionRole).value<Collection>().contentMimeTypes();
const QMimeData *mimeData = event->mimeData();
if (!mimeData) {
return;
}
const QList<QUrl> urls = mimeData->urls();
for (const QUrl &url : urls) {
const Collection collection = Collection::fromUrl(url);
if (collection.isValid()) {
if (!supportedContentTypes.contains(QLatin1String("inode/directory"))) {
break;
}
// Check if we don't try to drop on one of the children
if (d->hasParent(index, collection.id())) {
break;
}
} else {
const QList<QPair<QString, QString>> query = QUrlQuery(url).queryItems();
const int numberOfQuery(query.count());
for (int i = 0; i < numberOfQuery; ++i) {
if (query.at(i).first == QLatin1String("type")) {
const QString type = query.at(i).second;
if (!supportedContentTypes.contains(type)) {
break;
}
}
}
}
QTreeView::dragMoveEvent(event);
return;
}
event->setDropAction(Qt::IgnoreAction);
}
void CollectionView::dragLeaveEvent(QDragLeaveEvent *event)
{
d->dragExpandTimer.stop();
d->dragOverIndex = QModelIndex();
QTreeView::dragLeaveEvent(event);
}
void CollectionView::dropEvent(QDropEvent *event)
{
d->dragExpandTimer.stop();
d->dragOverIndex = QModelIndex();
// open a context menu offering different drop actions (move, copy and cancel)
// TODO If possible, hide non available actions ...
QMenu popup(this);
QAction *moveDropAction = popup.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18n("&Move here"));
QAction *copyDropAction = popup.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("&Copy here"));
popup.addSeparator();
popup.addAction(QIcon::fromTheme(QStringLiteral("process-stop")), i18n("Cancel"));
QAction *activatedAction = popup.exec(QCursor::pos());
if (activatedAction == moveDropAction) {
event->setDropAction(Qt::MoveAction);
} else if (activatedAction == copyDropAction) {
event->setDropAction(Qt::CopyAction);
} else {
return;
}
QTreeView::dropEvent(event);
}
void CollectionView::contextMenuEvent(QContextMenuEvent *event)
{
if (!d->xmlGuiClient) {
return;
}
QMenu *popup = static_cast<QMenu *>(d->xmlGuiClient->factory()->container(QStringLiteral("akonadi_collectionview_contextmenu"), d->xmlGuiClient));
if (popup) {
popup->exec(event->globalPos());
}
}
void CollectionView::setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
{
d->xmlGuiClient = xmlGuiClient;
}
#include "moc_collectionview.cpp"
/*
SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "akonadiwidgets_export.h"
#include <QTreeView>
#include <memory>
class KXMLGUIClient;
class KXmlGuiWindow;
class QDragMoveEvent;
namespace Akonadi
{
class Collection;
/**
* @short A view to show a collection tree provided by a EntityTreeModel.
*
* When a KXmlGuiWindow is passed to the constructor, the XMLGUI
* defined context menu @c akonadi_collectionview_contextmenu is
* used if available.
*
* Example:
*
* @code
*
* class MyWindow : public KXmlGuiWindow
* {
* public:
* MyWindow()
* : KXmlGuiWindow()
* {
* Akonadi::CollectionView *view = new Akonadi::CollectionView(this, this);
* setCentralWidget(view);
*
* Akonadi::Monitor *monitor = new Akonadi::Monitor(this);
* Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel(monitor, this);
* view->setModel(model);
* }
* }
*
* @endcode
*
* @deprecated Use EntityTreeView or EntityListView on top of EntityTreeModel instead.
*
* @author Volker Krause <vkrause@kde.org>
*/
class AKONADIWIDGETS_DEPRECATED_EXPORT CollectionView : public QTreeView
{
Q_OBJECT
public:
/**
* Creates a new collection view.
*
* @param parent The parent widget.
*/
explicit CollectionView(QWidget *parent = nullptr);
/**
* Creates a new collection view.
*
* @param xmlGuiClient The KXmlGuiClient the view is used in.
* This is needed for the XMLGUI based context menu.
* Passing 0 is ok and will disable the builtin context menu.
* @param parent The parent widget.
*/
explicit CollectionView(KXMLGUIClient *xmlGuiClient, QWidget *parent = nullptr);
/**
* Destroys the collection view.
*/
~CollectionView() override;
/**
* Sets the KXMLGUIClient which the view is used in.
* This is needed if you want to use the built-in context menu.
*
* @param xmlGuiClient The KXMLGUIClient the view is used in.
* @since 4.3
*/
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
void setModel(QAbstractItemModel *model) override;
Q_SIGNALS:
/**
* This signal is emitted whenever the user has clicked
* a collection in the view.
*
* @param collection The clicked collection.
*/
void clicked(const Akonadi::Collection &collection);
/**
* This signal is emitted whenever the current collection
* in the view has changed.
*
* @param collection The new current collection.
*/
void currentChanged(const Akonadi::Collection &collection);
protected:
using QTreeView::currentChanged;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
private:
/// @cond PRIVATE
class Private;
std::unique_ptr<Private> const d;
Q_PRIVATE_SLOT(d, void itemClicked(const QModelIndex &))
Q_PRIVATE_SLOT(d, void itemCurrentChanged(const QModelIndex &))
/// @endcond
};
}
/*
SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "itemview.h"
#include "controlgui.h"
#include "entitytreemodel.h"
#include <KXMLGUIClient>
#include <KXMLGUIFactory>
#include <QContextMenuEvent>
#include <QHeaderView>
#include <QMenu>
using namespace Akonadi;
/**
* @internal
*/
class Q_DECL_HIDDEN ItemView::Private
{
public:
explicit Private(ItemView *parent)
: mParent(parent)
{
}
void init();
void itemActivated(const QModelIndex &index);
void itemCurrentChanged(const QModelIndex &index);
void itemClicked(const QModelIndex &index);
void itemDoubleClicked(const QModelIndex &index);
Item itemForIndex(const QModelIndex &index);
KXMLGUIClient *xmlGuiClient = nullptr;
private:
ItemView *const mParent;
};
void ItemView::Private::init()
{
mParent->setRootIsDecorated(false);
mParent->header()->setSectionsClickable(true);
mParent->header()->setStretchLastSection(true);
mParent->connect(mParent, &QAbstractItemView::activated, mParent, [this](const auto &index) {
itemActivated(index);
});
mParent->connect(mParent, &QAbstractItemView::clicked, mParent, [this](const auto &index) {
itemClicked(index);
});
mParent->connect(mParent, &QAbstractItemView::doubleClicked, mParent, [this](const auto &index) {
itemDoubleClicked(index);
});
ControlGui::widgetNeedsAkonadi(mParent);
}
Item ItemView::Private::itemForIndex(const QModelIndex &index)
{
if (!index.isValid()) {
return Item();
}
return mParent->model()->data(index, EntityTreeModel::ItemRole).value<Item>();
}
void ItemView::Private::itemActivated(const QModelIndex &index)
{
const Item item = itemForIndex(index);
if (!item.isValid()) {
return;
}
Q_EMIT mParent->activated(item);
}
void ItemView::Private::itemCurrentChanged(const QModelIndex &index)
{
const Item item = itemForIndex(index);
if (!item.isValid()) {
return;
}
Q_EMIT mParent->currentChanged(item);
}
void ItemView::Private::itemClicked(const QModelIndex &index)
{
const Item item = itemForIndex(index);
if (!item.isValid()) {
return;
}
Q_EMIT mParent->clicked(item);
}
void ItemView::Private::itemDoubleClicked(const QModelIndex &index)
{
const Item item = itemForIndex(index);
if (!item.isValid()) {
return;
}
Q_EMIT mParent->doubleClicked(item);
}
ItemView::ItemView(QWidget *parent)
: QTreeView(parent)
, d(new Private(this))
{
d->init();
}
ItemView::ItemView(KXMLGUIClient *xmlGuiClient, QWidget *parent)
: QTreeView(parent)
, d(new Private(this))
{
d->xmlGuiClient = xmlGuiClient;
d->init();
}
ItemView::~ItemView() = default;
void ItemView::setModel(QAbstractItemModel *model)
{
if (selectionModel()) {
disconnect(selectionModel(), &QItemSelectionModel::currentChanged, this, nullptr);
}
QTreeView::setModel(model);
connect(selectionModel(), &QItemSelectionModel::currentChanged, this, [this](const auto &index) {
d->itemCurrentChanged(index);
});
}
void ItemView::contextMenuEvent(QContextMenuEvent *event)
{
if (!d->xmlGuiClient) {
return;
}
QMenu *popup = static_cast<QMenu *>(d->xmlGuiClient->factory()->container(QStringLiteral("akonadi_itemview_contextmenu"), d->xmlGuiClient));
if (popup) {
popup->exec(event->globalPos());
}
}
void ItemView::setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
{
d->xmlGuiClient = xmlGuiClient;
}
#include "moc_itemview.cpp"
/*
SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "akonadiwidgets_export.h"
#include <QTreeView>
#include <memory>
class KXmlGuiWindow;
class KXMLGUIClient;
namespace Akonadi
{
class Item;
/**
* @short A view to show an item list provided by an ItemModel.
*
* When a KXmlGuiWindow is set, the XMLGUI defined context menu
* @c akonadi_itemview_contextmenu is used if available.
*
* Example:
*
* @code
*
* class MyWindow : public KXmlGuiWindow
* {
* public:
* MyWindow()
* : KXmlGuiWindow()
* {
* Akonadi::ItemView *view = new Akonadi::ItemView( this, this );
* setCentralWidget( view );
*
* Akonadi::ItemModel *model = new Akonadi::ItemModel( this );
* view->setModel( model );
* }
* }
*
* @endcode
*
* @deprecated Use EntityTreeView or EntityListView on top of EntityTreeModel instead.
*
* @author Tobias Koenig <tokoe@kde.org>
*/
class AKONADIWIDGETS_DEPRECATED_EXPORT ItemView : public QTreeView
{
Q_OBJECT