diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 90602505..fb4c4351 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -208,7 +208,6 @@ install( KNumInput KOpenWithDialog KPageDialog - KPageModel KPageView KPageWidget KPageWidgetItem diff --git a/includes/KPageModel b/includes/KPageModel deleted file mode 100644 index 6c0ccb6d..00000000 --- a/includes/KPageModel +++ /dev/null @@ -1 +0,0 @@ -#include "../kpagemodel.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 59b07752..9806beb2 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -161,7 +161,6 @@ set(kdeui_LIB_SRCS notifications/kdbusmenuimporter.cpp notifications/kdbusmenu_p.cpp paged/kpagedialog.cpp - paged/kpagemodel.cpp paged/kpageview.cpp paged/kpageview_p.cpp paged/kpagewidget.cpp @@ -498,7 +497,6 @@ install( notifications/kdbusmenuexporter.h notifications/kdbusmenuimporter.h paged/kpagedialog.h - paged/kpagemodel.h paged/kpageview.h paged/kpagewidget.h paged/kpagewidgetmodel.h diff --git a/kdeui/paged/kpagemodel.cpp b/kdeui/paged/kpagemodel.cpp deleted file mode 100644 index e8f7b4b2..00000000 --- a/kdeui/paged/kpagemodel.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - This file is part of the KDE Libraries - - Copyright (C) 2006 Tobias Koenig (tokoe@kde.org) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kpagemodel.h" -#include "kpagemodel_p.h" - -KPageModelPrivate::~KPageModelPrivate() -{ -} - -KPageModel::KPageModel( QObject *parent ) - : QAbstractItemModel(parent), d_ptr(0) -{ -} - -KPageModel::KPageModel(KPageModelPrivate &dd, QObject *parent) - : QAbstractItemModel(parent), d_ptr(&dd) -{ - d_ptr->q_ptr = this; -} - -KPageModel::~KPageModel() -{ - delete d_ptr; -} - -#include "moc_kpagemodel.cpp" diff --git a/kdeui/paged/kpagemodel.h b/kdeui/paged/kpagemodel.h deleted file mode 100644 index 6645c4ea..00000000 --- a/kdeui/paged/kpagemodel.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - This file is part of the KDE Libraries - - Copyright (C) 2006 Tobias Koenig (tokoe@kde.org) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPAGEMODEL_H -#define KPAGEMODEL_H - -#include - -#include - -class KPageModelPrivate; - -/** - * @short A base class for a model used by KPageView. - * - * This class is an abstract base class which must be used to - * implement custom models for KPageView. Additional to the standard - * Qt::ItemDataRoles it provides the two roles - * - * @li HeaderRole - * @li WidgetRole - * - * which are used to return a header string for a page and a QWidget - * pointer to the page itself. - * - * Example:\n - * - * \code - * KPageView *view = new KPageView( this ); - * KPageModel *model = new MyPageModel( this ); - * - * view->setModel( model ); - * \endcode - * - * @see KPageView - * @author Tobias Koenig - */ -class KDEUI_EXPORT KPageModel : public QAbstractItemModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(KPageModel) - - public: - /** - * Additional roles that KPageView uses. - */ - enum Role { - /** - * A string to be rendered as page header. - */ - HeaderRole = Qt::UserRole + 1, - /** - * A pointer to the page widget. This is the widget that is shown when the item is - * selected. - * - * You can make QVariant take a QWidget using - * \code - * QWidget *myWidget = new QWidget; - * QVariant v = QVariant::fromValue(myWidget); - * \endcode - */ - WidgetRole - }; - - /** - * Constructs a page model with the given parent. - */ - explicit KPageModel( QObject *parent = 0 ); - - /** - * Destroys the page model. - */ - virtual ~KPageModel(); - - protected: - KPageModel(KPageModelPrivate &dd, QObject *parent); - KPageModelPrivate *const d_ptr; -}; - -#endif diff --git a/kdeui/paged/kpagemodel_p.h b/kdeui/paged/kpagemodel_p.h deleted file mode 100644 index 9b5c6c87..00000000 --- a/kdeui/paged/kpagemodel_p.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef KPAGEMODEL_P_H -#define KPAGEMODEL_P_H - -#include "kpagemodel.h" - -class KPageModelPrivate -{ - Q_DECLARE_PUBLIC(KPageModel) - public: - virtual ~KPageModelPrivate(); - - protected: - KPageModel *q_ptr; -}; - -#endif // KPAGEMODEL_P_H diff --git a/kdeui/paged/kpageview.cpp b/kdeui/paged/kpageview.cpp index f46a43a8..9da43988 100644 --- a/kdeui/paged/kpageview.cpp +++ b/kdeui/paged/kpageview.cpp @@ -23,8 +23,6 @@ #include "kpageview.h" #include "kpageview_p.h" -#include "kpagemodel.h" - #include #include #include @@ -141,7 +139,7 @@ QList KPageViewPrivate::collectPages(const QModelIndex &parentIndex) int rows = model->rowCount( parentIndex ); for ( int j = 0; j < rows; ++j ) { const QModelIndex index = model->index( j, 0, parentIndex ); - retval.append( qvariant_cast( model->data( index, KPageModel::WidgetRole ) ) ); + retval.append( qvariant_cast( model->data( index, KPageView::WidgetRole ) ) ); if ( model->rowCount( index ) > 0 ) { retval += collectPages( index ); @@ -225,7 +223,7 @@ void KPageViewPrivate::_k_pageSelected(const QItemSelection &index, const QItemS } if (faceType != KPageView::Tabbed) { - QWidget *widget = qvariant_cast( model->data( currentIndex, KPageModel::WidgetRole ) ); + QWidget *widget = qvariant_cast( model->data( currentIndex, KPageView::WidgetRole ) ); if ( widget ) { if ( stack->indexOf( widget ) == -1 ) { // not included yet @@ -248,7 +246,7 @@ void KPageViewPrivate::updateTitleWidget(const QModelIndex& index) { Q_Q(KPageView); - QString header = model->data( index, KPageModel::HeaderRole ).toString(); + QString header = model->data( index, KPageView::HeaderRole ).toString(); if ( header.isNull() ) { //TODO KDE5 remove that ugly logic, see also doxy-comments in KPageWidgetItem::setHeader() header = model->data( index, Qt::DisplayRole ).toString(); } diff --git a/kdeui/paged/kpageview.h b/kdeui/paged/kpageview.h index 6e52e2b4..7ae4e4fc 100644 --- a/kdeui/paged/kpageview.h +++ b/kdeui/paged/kpageview.h @@ -24,16 +24,14 @@ #include -#include - -class KPageModel; - +#include #include #include #include -class KPageViewPrivate; #include +class KPageViewPrivate; + /** * @short A base class which can handle multiple pages. * @@ -41,13 +39,21 @@ class KPageViewPrivate; * pages and allows the user to switch between these pages in * different ways. * + * Additional to the standard Qt::ItemDataRoles it provides the two roles + * + * @li HeaderRole + * @li WidgetRole + * + * which are used to return a header string for a page and a QWidget + * pointer to the page itself. + * * Currently, @p Auto, @p Plain, @p List, @p Tree and @p Tabbed face * types are available. @see KPageWidget * * Example:\n * * \code - * KPageModel *model = new MyPageModel(); + * QAbstractItemModel *model = new MyPageModel(); * * KPageView *view = new KPageView( this ); * view->setModel( model ); @@ -59,12 +65,33 @@ class KPageViewPrivate; */ class KDEUI_EXPORT KPageView : public QWidget { - Q_OBJECT - Q_ENUMS( FaceType ) - Q_PROPERTY( FaceType faceType READ faceType WRITE setFaceType ) + Q_OBJECT + Q_ENUMS( FaceType ) + Q_PROPERTY( FaceType faceType READ faceType WRITE setFaceType ) Q_DECLARE_PRIVATE(KPageView) public: + /** + * Additional roles that KPageView uses. + */ + enum Role { + /** + * A string to be rendered as page header. + */ + HeaderRole = Qt::UserRole + 1, + /** + * A pointer to the page widget. This is the widget that is shown when the item is + * selected. + * + * You can make QVariant take a QWidget using + * \code + * QWidget *myWidget = new QWidget; + * QVariant v = QVariant::fromValue(myWidget); + * \endcode + */ + WidgetRole + }; + /** * This enum is used to decide which type of navigation view * shall be used in the page view. @@ -104,7 +131,7 @@ class KDEUI_EXPORT KPageView : public QWidget /** * Sets the @p model of the page view. * - * The model has to provide data for the roles defined in KPageModel::Role. + * The model has to provide data for the roles defined in KPageView::Role. */ void setModel(QAbstractItemModel *model); diff --git a/kdeui/paged/kpageview_p.cpp b/kdeui/paged/kpageview_p.cpp index d56d1b90..68d47841 100644 --- a/kdeui/paged/kpageview_p.cpp +++ b/kdeui/paged/kpageview_p.cpp @@ -32,8 +32,6 @@ #include #include -#include "kpagemodel.h" - using namespace KDEPrivate; /** @@ -224,7 +222,7 @@ KPageTabbedView::~KPageTabbedView() { if (model()) { for ( int i = 0; i < mTabWidget->count(); ++i ) { - QWidget *page = qvariant_cast( model()->data( model()->index( i, 0 ), KPageModel::WidgetRole ) ); + QWidget *page = qvariant_cast( model()->data( model()->index( i, 0 ), KPageView::WidgetRole ) ); if (page) { page->setVisible(false); @@ -326,7 +324,7 @@ void KPageTabbedView::layoutChanged() for ( int i = 0; i < model()->rowCount(); ++i ) { const QString title = model()->data( model()->index( i, 0 ) ).toString(); const QIcon icon = model()->data( model()->index( i, 0 ), Qt::DecorationRole ).value(); - QWidget *page = qvariant_cast( model()->data( model()->index( i, 0 ), KPageModel::WidgetRole ) ); + QWidget *page = qvariant_cast( model()->data( model()->index( i, 0 ), KPageView::WidgetRole ) ); if (page) { QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); diff --git a/kdeui/paged/kpagewidgetmodel.cpp b/kdeui/paged/kpagewidgetmodel.cpp index 381f4ceb..884525e7 100644 --- a/kdeui/paged/kpagewidgetmodel.cpp +++ b/kdeui/paged/kpagewidgetmodel.cpp @@ -252,12 +252,15 @@ void PageItem::dump( int indent ) } KPageWidgetModel::KPageWidgetModel( QObject *parent ) - : KPageModel(*new KPageWidgetModelPrivate, parent) + : QAbstractItemModel(parent), + d_ptr(new KPageWidgetModelPrivate()) { + d_ptr->q_ptr = this; } KPageWidgetModel::~KPageWidgetModel() { + delete d_ptr; } int KPageWidgetModel::columnCount( const QModelIndex& ) const @@ -276,9 +279,9 @@ QVariant KPageWidgetModel::data( const QModelIndex &index, int role ) const return QVariant( item->pageWidgetItem()->name() ); else if ( role == Qt::DecorationRole ) return QVariant( item->pageWidgetItem()->icon() ); - else if ( role == HeaderRole ) + else if ( role == KPageView::HeaderRole ) return QVariant( item->pageWidgetItem()->header() ); - else if ( role == WidgetRole ) + else if ( role == KPageView::WidgetRole ) return QVariant::fromValue( item->pageWidgetItem()->widget() ); else if ( role == Qt::CheckStateRole ) { if ( item->pageWidgetItem()->isCheckable() ) { diff --git a/kdeui/paged/kpagewidgetmodel.h b/kdeui/paged/kpagewidgetmodel.h index 94bbf94d..c4f03918 100644 --- a/kdeui/paged/kpagewidgetmodel.h +++ b/kdeui/paged/kpagewidgetmodel.h @@ -22,9 +22,10 @@ #ifndef KPAGEWIDGETMODEL_H #define KPAGEWIDGETMODEL_H -#include "kpagemodel.h" +#include #include +#include class KIcon; @@ -185,7 +186,7 @@ class KPageWidgetModelPrivate; * This page model is used by @see KPageWidget to provide * a hierarchical layout of pages. */ -class KDEUI_EXPORT KPageWidgetModel : public KPageModel +class KDEUI_EXPORT KPageWidgetModel : public QAbstractItemModel { Q_OBJECT Q_DECLARE_PRIVATE(KPageWidgetModel) @@ -297,6 +298,8 @@ class KDEUI_EXPORT KPageWidgetModel : public KPageModel void toggled( KPageWidgetItem *page, bool checked ); private: + KPageWidgetModelPrivate *const d_ptr; + Q_PRIVATE_SLOT(d_func(), void _k_itemChanged()) Q_PRIVATE_SLOT(d_func(), void _k_itemToggled(bool)) }; diff --git a/kdeui/paged/kpagewidgetmodel_p.h b/kdeui/paged/kpagewidgetmodel_p.h index 40c5facc..06b959e9 100644 --- a/kdeui/paged/kpagewidgetmodel_p.h +++ b/kdeui/paged/kpagewidgetmodel_p.h @@ -20,8 +20,7 @@ #ifndef KPAGEWIDGETMODEL_P_H #define KPAGEWIDGETMODEL_P_H -#include "kpagemodel_p.h" -#include "kpagewidgetmodel.h" +#include "kpageview.h" class PageItem { @@ -52,7 +51,7 @@ class PageItem PageItem *mParentItem; }; -class KPageWidgetModelPrivate : public KPageModelPrivate +class KPageWidgetModelPrivate { Q_DECLARE_PUBLIC(KPageWidgetModel) protected: @@ -95,6 +94,9 @@ class KPageWidgetModelPrivate : public KPageModelPrivate emit q->toggled(item, checked); } + + protected: + KPageWidgetModel *q_ptr; }; #endif // KPAGEWIDGETMODEL_P_H