summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <gladhorn@kde.org>2016-10-08 12:50:50 (GMT)
committerFrederik Gladhorn <gladhorn@kde.org>2016-10-08 12:53:10 (GMT)
commitdc208c20e8df525c1053b73dace4d2beeef66092 (patch)
tree5cfdee7f26b02525bd5a019b40f09c160919409c
parentad3b07f3c88e6fa964bee08731e166e68cd295d9 (diff)
Remove FolderViewContextManagerItemPrivate
-rw-r--r--app/folderviewcontextmanageritem.cpp261
-rw-r--r--app/folderviewcontextmanageritem.h27
2 files changed, 139 insertions, 149 deletions
diff --git a/app/folderviewcontextmanageritem.cpp b/app/folderviewcontextmanageritem.cpp
index f42cbdb..ed36038 100644
--- a/app/folderviewcontextmanageritem.cpp
+++ b/app/folderviewcontextmanageritem.cpp
@@ -38,15 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sidebar.h"
#include "fileoperations.h"
-#define USE_PLACETREE
-#ifdef USE_PLACETREE
-#include <lib/placetreemodel.h>
-#define MODEL_CLASS PlaceTreeModel
-#else
-#include <lib/semanticinfo/sorteddirmodel.h>
-#define MODEL_CLASS SortedDirModel
-#endif
-
namespace Gwenview
{
@@ -105,137 +96,25 @@ private:
QRect mDropRect;
};
-struct FolderViewContextManagerItemPrivate
-{
- FolderViewContextManagerItem* q;
- MODEL_CLASS* mModel;
- QTreeView* mView;
-
- QUrl mUrlToSelect;
- QPersistentModelIndex mExpandingIndex;
-
- void setupModel()
- {
- mModel = new MODEL_CLASS(q);
- mView->setModel(mModel);
-#ifndef USE_PLACETREE
- for (int col = 1; col <= mModel->columnCount(); ++col) {
- mView->header()->setSectionHidden(col, true);
- }
- mModel->dirLister()->openUrl(QUrl("/"));
-#endif
- QObject::connect(mModel, &MODEL_CLASS::rowsInserted, q, &FolderViewContextManagerItem::slotRowsInserted);
- }
-
- void setupView()
- {
- mView = new UrlDropTreeView;
- mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
- mView->setAcceptDrops(true);
- mView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- mView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
-
- // Necessary to get the drop target highlighted
- mView->viewport()->setAttribute(Qt::WA_Hover);
-
- mView->setHeaderHidden(true);
-
- // This is tricky: QTreeView header has stretchLastSection set to true.
- // In this configuration, the header gets quite wide and cause an
- // horizontal scrollbar to appear.
- // To avoid this, set stretchLastSection to false and resizeMode to
- // Stretch (we still want the column to take the full width of the
- // widget).
- mView->header()->setStretchLastSection(false);
- mView->header()->setResizeMode(QHeaderView::ResizeToContents);
-
- q->setWidget(mView);
- QObject::connect(mView, &QTreeView::activated, q, &FolderViewContextManagerItem::slotActivated);
- EventWatcher::install(mView, QEvent::Show, q, SLOT(expandToSelectedUrl()));
- }
-
- QModelIndex findClosestIndex(const QModelIndex& parent, const QUrl &wantedUrl)
- {
- Q_ASSERT(mModel);
- QModelIndex index = parent;
- if (!index.isValid()) {
- index = findRootIndex(wantedUrl);
- if (!index.isValid()) {
- return QModelIndex();
- }
- }
-
- QUrl url = mModel->urlForIndex(index);
- if (!url.isParentOf(wantedUrl)) {
- qWarning() << url << "is not a parent of" << wantedUrl << "!";
- return QModelIndex();
- }
-
- QString relativePath = QDir(url.path()).relativeFilePath(wantedUrl.path());
- QModelIndex lastFoundIndex = index;
- Q_FOREACH(const QString & pathPart, relativePath.split(QDir::separator(), QString::SkipEmptyParts)) {
- bool found = false;
- for (int row = 0; row < mModel->rowCount(lastFoundIndex); ++row) {
- QModelIndex index = mModel->index(row, 0, lastFoundIndex);
- if (index.data().toString() == pathPart) {
- // FIXME: Check encoding
- found = true;
- lastFoundIndex = index;
- break;
- }
- }
- if (!found) {
- break;
- }
- }
- return lastFoundIndex;
- }
-
- QModelIndex findRootIndex(const QUrl &wantedUrl)
- {
- QModelIndex matchIndex;
- int matchUrlLength = 0;
- for (int row = 0; row < mModel->rowCount(); ++row) {
- QModelIndex index = mModel->index(row, 0);
- QUrl url = mModel->urlForIndex(index);
- int urlLength = url.url().length();
- if (url.isParentOf(wantedUrl) && urlLength > matchUrlLength) {
- matchIndex = index;
- matchUrlLength = urlLength;
- }
- }
- if (!matchIndex.isValid()) {
- qWarning() << "Found no root index for" << wantedUrl;
- }
- return matchIndex;
- }
-};
FolderViewContextManagerItem::FolderViewContextManagerItem(ContextManager* manager)
: AbstractContextManagerItem(manager)
-, d(new FolderViewContextManagerItemPrivate)
{
- d->q = this;
- d->mModel = 0;
+ mModel = 0;
- d->setupView();
+ setupView();
connect(contextManager(), SIGNAL(currentDirUrlChanged(QUrl)),
SLOT(slotCurrentDirUrlChanged(QUrl)));
}
-FolderViewContextManagerItem::~FolderViewContextManagerItem()
-{
- delete d;
-}
-
void FolderViewContextManagerItem::slotCurrentDirUrlChanged(const QUrl &url)
{
- if (url.isValid() && d->mUrlToSelect != url) {
- d->mUrlToSelect = url.adjusted(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments);
- d->mExpandingIndex = QModelIndex();
+ if (url.isValid() && mUrlToSelect != url) {
+ mUrlToSelect = url.adjusted(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments);
+ mExpandingIndex = QModelIndex();
}
- if (!d->mView->isVisible()) {
+ if (!mView->isVisible()) {
return;
}
@@ -244,31 +123,31 @@ void FolderViewContextManagerItem::slotCurrentDirUrlChanged(const QUrl &url)
void FolderViewContextManagerItem::expandToSelectedUrl()
{
- if (!d->mUrlToSelect.isValid()) {
+ if (!mUrlToSelect.isValid()) {
return;
}
- if (!d->mModel) {
- d->setupModel();
+ if (!mModel) {
+ setupModel();
}
- QModelIndex index = d->findClosestIndex(d->mExpandingIndex, d->mUrlToSelect);
+ QModelIndex index = findClosestIndex(mExpandingIndex, mUrlToSelect);
if (!index.isValid()) {
return;
}
- d->mExpandingIndex = index;
+ mExpandingIndex = index;
- QUrl url = d->mModel->urlForIndex(d->mExpandingIndex);
- if (d->mUrlToSelect == url) {
+ QUrl url = mModel->urlForIndex(mExpandingIndex);
+ if (mUrlToSelect == url) {
// We found our url
- QItemSelectionModel* selModel = d->mView->selectionModel();
- selModel->setCurrentIndex(d->mExpandingIndex, QItemSelectionModel::ClearAndSelect);
- d->mView->scrollTo(d->mExpandingIndex);
- d->mUrlToSelect = QUrl();
- d->mExpandingIndex = QModelIndex();
+ QItemSelectionModel* selModel = mView->selectionModel();
+ selModel->setCurrentIndex(mExpandingIndex, QItemSelectionModel::ClearAndSelect);
+ mView->scrollTo(mExpandingIndex);
+ mUrlToSelect = QUrl();
+ mExpandingIndex = QModelIndex();
} else {
// We found a parent of our url
- d->mView->setExpanded(d->mExpandingIndex, true);
+ mView->setExpanded(mExpandingIndex, true);
}
}
@@ -278,8 +157,8 @@ void FolderViewContextManagerItem::slotRowsInserted(const QModelIndex& parentInd
// probably happen when root items are created. In this case we trigger
// expandToSelectedUrl without checking the url.
// See bug #191771
- if (!parentIndex.isValid() || d->mModel->urlForIndex(parentIndex).isParentOf(d->mUrlToSelect)) {
- d->mExpandingIndex = parentIndex;
+ if (!parentIndex.isValid() || mModel->urlForIndex(parentIndex).isParentOf(mUrlToSelect)) {
+ mExpandingIndex = parentIndex;
// Hack because otherwise indexes are not in correct order!
QMetaObject::invokeMethod(this, "expandToSelectedUrl", Qt::QueuedConnection);
}
@@ -291,8 +170,104 @@ void FolderViewContextManagerItem::slotActivated(const QModelIndex& index)
return;
}
- QUrl url = d->mModel->urlForIndex(index);
+ QUrl url = mModel->urlForIndex(index);
emit urlChanged(url);
}
+void FolderViewContextManagerItem::setupModel()
+{
+ mModel = new MODEL_CLASS(this);
+ mView->setModel(mModel);
+#ifndef USE_PLACETREE
+ for (int col = 1; col <= mModel->columnCount(); ++col) {
+ mView->header()->setSectionHidden(col, true);
+ }
+ mModel->dirLister()->openUrl(QUrl("/"));
+#endif
+ QObject::connect(mModel, &MODEL_CLASS::rowsInserted, this, &FolderViewContextManagerItem::slotRowsInserted);
+}
+
+void FolderViewContextManagerItem::setupView()
+{
+ mView = new UrlDropTreeView;
+ mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ mView->setAcceptDrops(true);
+ mView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+ mView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+
+ // Necessary to get the drop target highlighted
+ mView->viewport()->setAttribute(Qt::WA_Hover);
+
+ mView->setHeaderHidden(true);
+
+ // This is tricky: QTreeView header has stretchLastSection set to true.
+ // In this configuration, the header gets quite wide and cause an
+ // horizontal scrollbar to appear.
+ // To avoid this, set stretchLastSection to false and resizeMode to
+ // Stretch (we still want the column to take the full width of the
+ // widget).
+ mView->header()->setStretchLastSection(false);
+ mView->header()->setResizeMode(QHeaderView::ResizeToContents);
+
+ setWidget(mView);
+ QObject::connect(mView, &QTreeView::activated, this, &FolderViewContextManagerItem::slotActivated);
+ EventWatcher::install(mView, QEvent::Show, this, SLOT(expandToSelectedUrl()));
+}
+
+QModelIndex FolderViewContextManagerItem::findClosestIndex(const QModelIndex& parent, const QUrl& wantedUrl)
+{
+ Q_ASSERT(mModel);
+ QModelIndex index = parent;
+ if (!index.isValid()) {
+ index = findRootIndex(wantedUrl);
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ }
+
+ QUrl url = mModel->urlForIndex(index);
+ if (!url.isParentOf(wantedUrl)) {
+ qWarning() << url << "is not a parent of" << wantedUrl << "!";
+ return QModelIndex();
+ }
+
+ QString relativePath = QDir(url.path()).relativeFilePath(wantedUrl.path());
+ QModelIndex lastFoundIndex = index;
+ Q_FOREACH(const QString & pathPart, relativePath.split(QDir::separator(), QString::SkipEmptyParts)) {
+ bool found = false;
+ for (int row = 0; row < mModel->rowCount(lastFoundIndex); ++row) {
+ QModelIndex index = mModel->index(row, 0, lastFoundIndex);
+ if (index.data().toString() == pathPart) {
+ // FIXME: Check encoding
+ found = true;
+ lastFoundIndex = index;
+ break;
+ }
+ }
+ if (!found) {
+ break;
+ }
+ }
+ return lastFoundIndex;
+}
+
+QModelIndex FolderViewContextManagerItem::findRootIndex(const QUrl& wantedUrl)
+{
+ QModelIndex matchIndex;
+ int matchUrlLength = 0;
+ for (int row = 0; row < mModel->rowCount(); ++row) {
+ QModelIndex index = mModel->index(row, 0);
+ QUrl url = mModel->urlForIndex(index);
+ int urlLength = url.url().length();
+ if (url.isParentOf(wantedUrl) && urlLength > matchUrlLength) {
+ matchIndex = index;
+ matchUrlLength = urlLength;
+ }
+ }
+ if (!matchIndex.isValid()) {
+ qWarning() << "Found no root index for" << wantedUrl;
+ }
+ return matchIndex;
+}
+
} // namespace
diff --git a/app/folderviewcontextmanageritem.h b/app/folderviewcontextmanageritem.h
index b120d61..466ec42 100644
--- a/app/folderviewcontextmanageritem.h
+++ b/app/folderviewcontextmanageritem.h
@@ -22,26 +22,33 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define FOLDERVIEWCONTEXTMANAGERITEM_H
// Qt
+#include <QUrl>
// KDE
// Local
#include "abstractcontextmanageritem.h"
-class QModelIndex;
+#define USE_PLACETREE
+#ifdef USE_PLACETREE
+#include <lib/placetreemodel.h>
+#define MODEL_CLASS PlaceTreeModel
+#else
+#include <lib/semanticinfo/sorteddirmodel.h>
+#define MODEL_CLASS SortedDirModel
+#endif
-class QUrl;
+class QModelIndex;
+class QTreeView;
namespace Gwenview
{
-struct FolderViewContextManagerItemPrivate;
class FolderViewContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
FolderViewContextManagerItem(ContextManager*);
- ~FolderViewContextManagerItem();
Q_SIGNALS:
void urlChanged(const QUrl&);
@@ -53,8 +60,16 @@ private Q_SLOTS:
void slotActivated(const QModelIndex&);
private:
- friend struct FolderViewContextManagerItemPrivate;
- FolderViewContextManagerItemPrivate* const d;
+ MODEL_CLASS* mModel;
+ QTreeView* mView;
+
+ QUrl mUrlToSelect;
+ QPersistentModelIndex mExpandingIndex;
+
+ void setupModel();
+ void setupView();
+ QModelIndex findClosestIndex(const QModelIndex& parent, const QUrl &wantedUrl);
+ QModelIndex findRootIndex(const QUrl &wantedUrl);
};
} // namespace