• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/kabc

collectioncombobox.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "collectioncombobox.h"
00021 
00022 #include <QtCore/QAbstractItemModel>
00023 #include <QtGui/QComboBox>
00024 #include <QtGui/QVBoxLayout>
00025 
00026 #include <akonadi/collectionmodel.h>
00027 
00028 using namespace Akonadi;
00029 using namespace KABC;
00030 
00031 class CollectionComboBox::Private
00032 {
00033   public:
00034     Private( CollectionComboBox *parent )
00035       : mParent( parent )
00036     {
00037     }
00038 
00039     void activated( int index );
00040 
00041     CollectionComboBox *mParent;
00042 
00043     QComboBox *mComboBox;
00044 };
00045 
00046 void CollectionComboBox::Private::activated( int index )
00047 {
00048   if ( !mComboBox->model() )
00049     return;
00050 
00051   const QModelIndex modelIndex = mComboBox->model()->index( index, 0 );
00052   if ( modelIndex.isValid() )
00053     emit mParent->selectionChanged( Collection( modelIndex.data( CollectionModel::CollectionIdRole ).toLongLong() ) );
00054 }
00055 
00056 CollectionComboBox::CollectionComboBox( QWidget *parent )
00057   : QWidget( parent ), d( new Private( this ) )
00058 {
00059   QVBoxLayout *layout = new QVBoxLayout( this );
00060   layout->setMargin( 0 );
00061   layout->setSpacing( 0 );
00062 
00063   d->mComboBox = new QComboBox( this );
00064   layout->addWidget( d->mComboBox );
00065 
00066   connect( d->mComboBox, SIGNAL( activated( int ) ), SLOT( activated( int ) ) );
00067 }
00068 
00069 CollectionComboBox::~CollectionComboBox()
00070 {
00071   delete d;
00072 }
00073 
00074 void CollectionComboBox::setModel( QAbstractItemModel *model )
00075 {
00076   d->mComboBox->setModel( model );
00077 }
00078 
00079 Akonadi::Collection CollectionComboBox::selectedCollection() const
00080 {
00081   Q_ASSERT_X( d->mComboBox->model() != 0, "CollectionComboBox::selectionChanged", "No model set!" );
00082 
00083   int index = d->mComboBox->currentIndex();
00084 
00085   const QModelIndex modelIndex = d->mComboBox->model()->index( index, 0 );
00086   if ( modelIndex.isValid() )
00087     return Akonadi::Collection( modelIndex.data( Akonadi::CollectionModel::CollectionIdRole ).toLongLong() );
00088   else
00089     return Akonadi::Collection();
00090 }
00091 
00092 #include "collectioncombobox.moc"

akonadi/kabc

Skip menu "akonadi/kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal