23 #include "kpagewidgetmodel_p.h" 30 class KPageWidgetItem::Private
54 :
QObject( 0 ), d( new Private )
68 :
QObject( 0 ), d( new Private )
167 PageItem::PageItem(
KPageWidgetItem *pageWidgetItem, PageItem *parent )
168 : mPageWidgetItem( pageWidgetItem ), mParentItem( parent )
172 PageItem::~PageItem()
174 delete mPageWidgetItem;
177 qDeleteAll(mChildItems);
180 void PageItem::appendChild( PageItem *item )
182 mChildItems.append( item );
185 void PageItem::insertChild(
int row, PageItem *item )
187 mChildItems.insert( row, item );
190 void PageItem::removeChild(
int row )
192 mChildItems.removeAt( row );
195 PageItem *PageItem::child(
int row )
197 return mChildItems.value( row );
200 int PageItem::childCount()
const 202 return mChildItems.count();
205 int PageItem::columnCount()
const 210 PageItem *PageItem::parent()
215 int PageItem::row()
const 218 return mParentItem->mChildItems.indexOf( const_cast<PageItem*>(
this) );
225 return mPageWidgetItem;
230 if ( mPageWidgetItem == item )
233 for (
int i = 0; i < mChildItems.count(); ++i ) {
234 PageItem *pageItem = mChildItems[ i ]->findChild( item );
242 void PageItem::dump(
int indent )
245 for (
int i = 0; i <
indent; ++i )
248 const QString
name = ( mPageWidgetItem ? mPageWidgetItem->name() :
"root" );
249 qDebug(
"%s (%p)", qPrintable( QString(
"%1%2" ).arg( prefix,
name ) ), (
void*)
this );
250 for (
int i = 0; i < mChildItems.count(); ++i )
251 mChildItems[ i ]->dump( indent + 2 );
255 :
KPageModel(*new KPageWidgetModelPrivate, parent)
270 if ( !
index.isValid() )
273 PageItem *
item = static_cast<PageItem*>(
index.internalPointer() );
275 if ( role == Qt::DisplayRole )
276 return QVariant(
item->pageWidgetItem()->
name() );
277 else if ( role == Qt::DecorationRole )
278 return QVariant(
item->pageWidgetItem()->
icon() );
280 return QVariant(
item->pageWidgetItem()->
header() );
282 return QVariant::fromValue(
item->pageWidgetItem()->
widget() );
283 else if ( role == Qt::CheckStateRole ) {
285 return (
item->pageWidgetItem()->
isChecked() ? Qt::Checked : Qt::Unchecked );
294 if ( !
index.isValid() )
297 if ( role != Qt::CheckStateRole )
300 PageItem *
item = static_cast<PageItem*>(
index.internalPointer() );
307 if ( value.toInt() == Qt::Checked )
317 if ( !
index.isValid() )
320 Qt::ItemFlags
flags = Qt::ItemIsSelectable;
322 PageItem *
item = static_cast<PageItem*>(
index.internalPointer() );
324 flags |= Qt::ItemIsUserCheckable;
326 flags |= Qt::ItemIsEnabled;
334 PageItem *parentItem;
337 parentItem = static_cast<PageItem*>(
parent.internalPointer() );
339 parentItem = d_func()->rootItem;
341 PageItem *childItem = parentItem->child( row );
343 return createIndex( row, column, childItem );
345 return QModelIndex();
350 if ( !
index.isValid() )
351 return QModelIndex();
353 PageItem *
item = static_cast<PageItem*>(
index.internalPointer() );
354 PageItem *parentItem =
item->parent();
356 if ( parentItem == d_func()->rootItem )
357 return QModelIndex();
359 return createIndex( parentItem->row(), 0, parentItem );
364 PageItem *parentItem;
367 parentItem = d_func()->rootItem;
369 parentItem = static_cast<PageItem*>(
parent.internalPointer() );
371 return parentItem->childCount();
385 emit layoutAboutToBeChanged();
388 connect(
item, SIGNAL(changed()),
this, SLOT(_k_itemChanged()));
389 connect(
item, SIGNAL(
toggled(
bool)),
this, SLOT(_k_itemToggled(
bool)));
392 int row = d->rootItem->childCount();
394 beginInsertRows(QModelIndex(), row, row);
396 PageItem *pageItem =
new PageItem(
item, d->rootItem );
397 d->rootItem->appendChild( pageItem );
401 emit layoutChanged();
415 PageItem *beforePageItem = d_func()->rootItem->findChild(before);
416 if ( !beforePageItem ) {
417 qDebug(
"Invalid KPageWidgetItem passed!" );
421 emit layoutAboutToBeChanged();
423 connect(
item, SIGNAL(changed()),
this, SLOT(_k_itemChanged()));
424 connect(
item, SIGNAL(
toggled(
bool)),
this, SLOT(_k_itemToggled(
bool)));
426 PageItem *
parent = beforePageItem->parent();
428 int row = beforePageItem->row();
431 if (
parent != d_func()->rootItem) {
435 beginInsertRows(
index, row, row);
437 PageItem *newPageItem =
new PageItem(
item,
parent );
438 parent->insertChild( row, newPageItem );
442 emit layoutChanged();
456 PageItem *parentPageItem = d_func()->rootItem->findChild(
parent);
457 if ( !parentPageItem ) {
458 qDebug(
"Invalid KPageWidgetItem passed!" );
462 emit layoutAboutToBeChanged();
464 connect(
item, SIGNAL(changed()),
this, SLOT(_k_itemChanged()));
465 connect(
item, SIGNAL(
toggled(
bool)),
this, SLOT(_k_itemToggled(
bool)));
468 int row = parentPageItem->childCount();
471 if (parentPageItem != d_func()->rootItem) {
472 index = createIndex( parentPageItem->row(), 0, parentPageItem );
475 beginInsertRows(
index, row, row);
477 PageItem *newPageItem =
new PageItem(
item, parentPageItem );
478 parentPageItem->appendChild( newPageItem );
482 emit layoutChanged();
492 PageItem *pageItem = d->rootItem->findChild(
item );
494 qDebug(
"Invalid KPageWidgetItem passed!" );
498 emit layoutAboutToBeChanged();
500 disconnect(
item, SIGNAL(changed()),
this, SLOT(_k_itemChanged()));
501 disconnect(
item, SIGNAL(
toggled(
bool)),
this, SLOT(_k_itemToggled(
bool)));
503 PageItem *parentPageItem = pageItem->parent();
504 int row = parentPageItem->row();
507 if ( parentPageItem != d->rootItem )
508 index = createIndex( row, 0, parentPageItem );
510 beginRemoveRows(
index, pageItem->row(), pageItem->row());
512 parentPageItem->removeChild( pageItem->row() );
517 emit layoutChanged();
522 if ( !
index.isValid() )
525 PageItem *
item = static_cast<PageItem*>(
index.internalPointer() );
529 return item->pageWidgetItem();
535 return QModelIndex();
537 const PageItem *pageItem = d_func()->rootItem->findChild(
item);
539 return QModelIndex();
542 return createIndex( pageItem->row(), 0, (
void*)pageItem );
545 #include "kpagewidgetmodel.moc" KPageWidgetItem * item(const QModelIndex &index) const
Returns the.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void changed()
This signal is emitted whenever the icon or header is changed.
void setChecked(bool checked)
Sets whether the page widget item is checked.
KPageWidgetItem(QWidget *widget)
Creates a new page widget item.
QString name() const
Returns the name of the page widget item.
A base class for a model used by KPageView.
KIcon icon() const
Returns the icon of the page widget item.
const char * name(StandardAction id)
This will return the internal name of a given standard action.
~KPageWidgetItem()
Destroys the page widget item.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QString indent(QString text, int spaces)
void setEnabled(bool)
Sets whether the page widget item is enabled.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
These methods are reimplemented from QAbstractItemModel.
This page model is used by.
void toggled(bool checked)
This signal is emitted whenever the user checks or unchecks the item of.
void setIcon(const KIcon &icon)
Sets the icon of the page widget item.
bool enabled
This property holds whether the item is enabled.
bool isCheckable() const
Returns whether the page widget item is checkable.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
A wrapper around QIcon that provides KDE icon features.
KPageWidgetItem * addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
Inserts a new sub page in the model.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
A string to be rendered as page header.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void removePage(KPageWidgetItem *item)
Removes the page associated with the given.
QWidget * widget() const
Returns the widget of the page widget item.
KPageWidgetModel(QObject *parent=0)
Creates a new page widget model.
A pointer to the page widget.
bool isChecked() const
Returns whether the page widget item is checked.
KPageWidgetItem is used by KPageWidget and represents a page.
void toggled(KPageWidgetItem *page, bool checked)
This signal is emitted whenever a checkable page changes its state.
virtual QModelIndex parent(const QModelIndex &index) const
void setHeader(const QString &header)
Sets the header of the page widget item.
void setName(const QString &name)
Sets the name of the item as shown in the navigation view of the page widget.
KPageWidgetItem * addPage(QWidget *widget, const QString &name)
Adds a new top level page to the model.
QString header() const
Returns the header of the page widget item.
~KPageWidgetModel()
Destroys the page widget model.
void setCheckable(bool checkable)
Sets whether the page widget item is checkable in the view.
bool isEnabled() const
Returns whether the page widget item is enabled.
KPageWidgetItem * insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
Inserts a new page in the model.