diff --git a/src/svnfrontend/models/logitemmodel.h b/src/svnfrontend/models/logitemmodel.h index dbe691b9..71e60020 100644 --- a/src/svnfrontend/models/logitemmodel.h +++ b/src/svnfrontend/models/logitemmodel.h @@ -1,91 +1,91 @@ /*************************************************************************** * Copyright (C) 2007 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef LOG_ITEM_MODEL_H #define LOG_ITEM_MODEL_H #include #include #include "svnqt/svnqttypes.h" class SvnLogModelNode; class QTreeWidget; typedef QSharedPointer SvnLogModelNodePtr; -class SvnLogModel: public QAbstractListModel +class SvnLogModel final : public QAbstractListModel { Q_OBJECT public: SvnLogModel(const svn::LogEntriesMapPtr &_log, const QString &_name, QObject *parent); void setLogData(const svn::LogEntriesMapPtr &log, const QString &name); qlonglong toRevision(const QModelIndex &)const; const QString &fullMessage(const QModelIndex &index)const; void fillChangedPaths(const QModelIndex &index, QTreeWidget *target); const QString &realName(const QModelIndex &index); enum Columns { Author = 0, Revision, Date, Message, Count }; - QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; - int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + int columnCount(const QModelIndex &idx = QModelIndex()) const override; SvnLogModelNodePtr indexNode(const QModelIndex &)const; int leftRow() const; int rightRow() const; void setLeftRow(int); void setRightRow(int); qlonglong min() const; qlonglong max() const; private: QVector m_data; QString m_emptyString; qlonglong m_min, m_max; QString m_name; int m_left, m_right; friend class SvnLogSortModel; }; class SvnLogSortModel final : public QSortFilterProxyModel { Q_OBJECT public: using QSortFilterProxyModel::QSortFilterProxyModel; void setSourceModel(QAbstractItemModel *sourceModel) override final; protected: bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override final; private: SvnLogModel *m_sourceModel = nullptr; }; #endif diff --git a/src/svnfrontend/svntreeview.cpp b/src/svnfrontend/svntreeview.cpp index ffafe66b..9b9841dc 100644 --- a/src/svnfrontend/svntreeview.cpp +++ b/src/svnfrontend/svntreeview.cpp @@ -1,157 +1,147 @@ /*************************************************************************** * Copyright (C) 2005-2009 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "svntreeview.h" #include "models/svnitemmodel.h" #include "models/svnitemnode.h" #include #include #include #include #include #include #include #include #include #include -SvnTreeView::SvnTreeView(QWidget *parent) - : QTreeView(parent) -{ - -} - -SvnTreeView::~SvnTreeView() -{ -} - void SvnTreeView::startDrag(Qt::DropActions supportedActions) { // only one dragging at time static bool isDrag = false; if (isDrag) { return; } isDrag = true; const QModelIndexList indexes = selectionModel()->selectedRows(); if (!indexes.isEmpty()) { QMimeData *data = model()->mimeData(indexes); if (data == nullptr) { isDrag = false; return; } QDrag *drag = new QDrag(this); QPixmap pixmap; if (indexes.count() == 1) { QAbstractProxyModel *proxyModel = static_cast(model()); SvnItemModel *itemModel = static_cast(proxyModel->sourceModel()); const QModelIndex index = proxyModel->mapToSource(indexes.first()); SvnItemModelNode *item = itemModel->nodeForIndex(index); pixmap = item->getPixmap(KIconLoader::SizeMedium, false); } else { pixmap = QIcon::fromTheme(QStringLiteral("document-multiple")).pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium); } drag->setPixmap(pixmap); drag->setMimeData(data); drag->exec(supportedActions, Qt::IgnoreAction); } isDrag = false; } void SvnTreeView::dropEvent(QDropEvent *event) { if (!event->mimeData()->hasUrls()) { return; } QAbstractProxyModel *proxyModel = static_cast(model()); const QModelIndex index = indexAt(event->pos()); const QModelIndex index2(index.isValid() ? proxyModel->mapToSource(index) : QModelIndex()); QMap metaMap; Qt::DropAction action = event->dropAction(); const QList list = KUrlMimeData::urlsFromMimeData(event->mimeData(), KUrlMimeData::PreferLocalUrls, &metaMap); bool intern = false; if (metaMap.contains(QStringLiteral("kdesvn-source"))) { SvnItemModel *itemModel = static_cast(proxyModel->sourceModel()); QMap::const_iterator it = metaMap.constFind(QStringLiteral("kdesvn-id")); if (it != metaMap.constEnd() && it.value() == itemModel->uniqueIdentifier()) { intern = true; } } Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers(); QMetaObject::invokeMethod(this, "doDrop", Q_ARG(QList, list), Q_ARG(QModelIndex, index2), Q_ARG(bool, intern), Q_ARG(Qt::DropAction, action), Q_ARG(Qt::KeyboardModifiers, modifiers) ); event->acceptProposedAction(); } void SvnTreeView::doDrop(const QList &list, const QModelIndex &parent, bool intern, Qt::DropAction action, Qt::KeyboardModifiers modifiers) { if (intern && ((modifiers & Qt::ControlModifier) == 0) && ((modifiers & Qt::ShiftModifier) == 0)) { QMenu popup; QString seq = QKeySequence(Qt::ShiftModifier).toString(); seq.chop(1); // chop superfluous '+' QAction *popupMoveAction = new QAction(i18n("&Move Here") + QLatin1Char('\t') + seq, this); popupMoveAction->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); seq = QKeySequence(Qt::ControlModifier).toString(); seq.chop(1); QAction *popupCopyAction = new QAction(i18n("&Copy Here") + QLatin1Char('\t') + seq, this); popupCopyAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); QAction *popupCancelAction = new QAction(i18n("C&ancel") + QLatin1Char('\t') + QKeySequence(Qt::Key_Escape).toString(), this); popupCancelAction->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); popup.addAction(popupMoveAction); popup.addAction(popupCopyAction); popup.addSeparator(); popup.addAction(popupCancelAction); QAction *result = popup.exec(QCursor::pos()); if (result == popupCopyAction) { action = Qt::CopyAction; } else if (result == popupMoveAction) { action = Qt::MoveAction; } else if (result == popupCancelAction || !result) { return; } } QAbstractProxyModel *proxyModel = static_cast(model()); SvnItemModel *itemModel = static_cast(proxyModel->sourceModel()); QModelIndex _p; if (!parent.isValid() && (_p = rootIndex()).isValid()) { QAbstractProxyModel *proxyModel = static_cast(model()); _p = proxyModel->mapToSource(_p); } else { _p = parent; } itemModel->dropUrls(list, action, parent.row(), parent.column(), _p, intern); } diff --git a/src/svnfrontend/svntreeview.h b/src/svnfrontend/svntreeview.h index 1d7b04ab..350fd330 100644 --- a/src/svnfrontend/svntreeview.h +++ b/src/svnfrontend/svntreeview.h @@ -1,40 +1,39 @@ /*************************************************************************** * Copyright (C) 2005-2009 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef SVNTREEVIEW_H #define SVNTREEVIEW_H #include -class SvnTreeView: public QTreeView +class SvnTreeView final : public QTreeView { Q_OBJECT public: - explicit SvnTreeView(QWidget *parent = nullptr); - ~SvnTreeView(); + using QTreeView::QTreeView; protected: void startDrag(Qt::DropActions supportedActions) override; void dropEvent(QDropEvent *event) override; protected Q_SLOTS: void doDrop(const QList &, const QModelIndex &, bool, Qt::DropAction, Qt::KeyboardModifiers); }; #endif