mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: merge KPageModel into KPageView and KPageWidgetModel
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
a3010676d5
commit
6a18754f1b
12 changed files with 58 additions and 209 deletions
|
@ -208,7 +208,6 @@ install(
|
|||
KNumInput
|
||||
KOpenWithDialog
|
||||
KPageDialog
|
||||
KPageModel
|
||||
KPageView
|
||||
KPageWidget
|
||||
KPageWidgetItem
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../kpagemodel.h"
|
|
@ -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
|
||||
|
|
|
@ -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"
|
|
@ -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 <kdeui_export.h>
|
||||
|
||||
#include <QtCore/QAbstractItemModel>
|
||||
|
||||
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.
|
||||
*
|
||||
* <b>Example:</b>\n
|
||||
*
|
||||
* \code
|
||||
* KPageView *view = new KPageView( this );
|
||||
* KPageModel *model = new MyPageModel( this );
|
||||
*
|
||||
* view->setModel( model );
|
||||
* \endcode
|
||||
*
|
||||
* @see KPageView
|
||||
* @author Tobias Koenig <tokoe@kde.org>
|
||||
*/
|
||||
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
|
|
@ -1,35 +0,0 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2007 Matthias Kretz <kretz@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 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
|
|
@ -23,8 +23,6 @@
|
|||
#include "kpageview.h"
|
||||
#include "kpageview_p.h"
|
||||
|
||||
#include "kpagemodel.h"
|
||||
|
||||
#include <kdialog.h>
|
||||
#include <kiconloader.h>
|
||||
#include <ktitlewidget.h>
|
||||
|
@ -141,7 +139,7 @@ QList<QWidget *> 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<QWidget*>( model->data( index, KPageModel::WidgetRole ) ) );
|
||||
retval.append( qvariant_cast<QWidget*>( 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<QWidget*>( model->data( currentIndex, KPageModel::WidgetRole ) );
|
||||
QWidget *widget = qvariant_cast<QWidget*>( 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();
|
||||
}
|
||||
|
|
|
@ -24,16 +24,14 @@
|
|||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
class KPageModel;
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemDelegate>
|
||||
#include <QAbstractItemView>
|
||||
#include <QModelIndex>
|
||||
class KPageViewPrivate;
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
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
|
||||
*
|
||||
* <b>Example:</b>\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);
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#include <kiconloader.h>
|
||||
#include <kglobalsettings.h>
|
||||
|
||||
#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<QWidget*>( model()->data( model()->index( i, 0 ), KPageModel::WidgetRole ) );
|
||||
QWidget *page = qvariant_cast<QWidget*>( 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<QIcon>();
|
||||
QWidget *page = qvariant_cast<QWidget*>( model()->data( model()->index( i, 0 ), KPageModel::WidgetRole ) );
|
||||
QWidget *page = qvariant_cast<QWidget*>( model()->data( model()->index( i, 0 ), KPageView::WidgetRole ) );
|
||||
if (page) {
|
||||
QWidget *widget = new QWidget(this);
|
||||
QVBoxLayout *layout = new QVBoxLayout(widget);
|
||||
|
|
|
@ -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() ) {
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
#ifndef KPAGEWIDGETMODEL_H
|
||||
#define KPAGEWIDGETMODEL_H
|
||||
|
||||
#include "kpagemodel.h"
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
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))
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue