23 #include "kpagewidgetmodel_p.h" 30 class KPageWidgetItem::Private
54 :
QObject( 0 ), d( new Private )
68 :
QObject( 0 ), d( new Private )
91 d->widget->setEnabled(enabled);
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 )
246 prefix.append(
" " );
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 ) {
284 if ( item->pageWidgetItem()->isCheckable() ) {
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() );
304 if ( !item->pageWidgetItem()->isCheckable() )
307 if ( value.toInt() == Qt::Checked )
310 item->pageWidgetItem()->setChecked(
false );
317 if ( !index.isValid() )
320 Qt::ItemFlags
flags = Qt::ItemIsSelectable;
322 PageItem *item =
static_cast<PageItem*
>( index.internalPointer() );
323 if ( item->pageWidgetItem()->isCheckable() )
324 flags |= Qt::ItemIsUserCheckable;
325 if (item->pageWidgetItem()->isEnabled()) {
326 flags |= Qt::ItemIsEnabled;
334 PageItem *parentItem;
336 if ( parent.isValid() )
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;
366 if ( !parent.isValid() )
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) {
432 index = createIndex( parent->row(), 0,
parent );
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" QString header() const
Returns the header of the page widget item.
virtual Qt::ItemFlags flags(const QModelIndex &index) 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.
QString name() const
Returns the name of the page widget item.
KPageWidgetItem(QWidget *widget)
Creates a new page widget item.
A base class for a model used by KPageView.
const char * name(StandardAction id)
This will return the internal name of a given standard action.
KIcon icon() const
Returns the icon of the page widget item.
~KPageWidgetItem()
Destroys the page widget item.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
QString indent(QString text, int spaces)
void setEnabled(bool)
Sets whether the page widget item is enabled.
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.
virtual QModelIndex parent(const QModelIndex &index) const
bool enabled
This property holds whether the item is enabled.
bool isEnabled() const
Returns whether the page widget item is enabled.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
These methods are reimplemented from QAbstractItemModel.
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.
bool isChecked() const
Returns whether the page widget item is checked.
A string to be rendered as page header.
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.
KPageWidgetItem * item(const QModelIndex &index) const
Returns the.
A pointer to the page widget.
bool isCheckable() const
Returns whether the page widget item is checkable.
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.
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.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
~KPageWidgetModel()
Destroys the page widget model.
void setCheckable(bool checkable)
Sets whether the page widget item is checkable in the view.
KPageWidgetItem * insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
Inserts a new page in the model.