diff --git a/akonadi/CMakeLists.txt b/akonadi/CMakeLists.txt index e92f0c386..cf8506622 100644 --- a/akonadi/CMakeLists.txt +++ b/akonadi/CMakeLists.txt @@ -1,298 +1,297 @@ project(akonadi-kde) add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5250 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) if(CMAKE_COMPILE_GCOV) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") endif(CMAKE_COMPILE_GCOV) if (KDE4_BUILD_TESTS) # only with this macro the AKONADI_TESTS_EXPORT macro will do something add_definitions(-DCOMPILING_TESTS) add_subdirectory( tests ) endif (KDE4_BUILD_TESTS) add_definitions( -DQT_NO_CAST_FROM_ASCII ) add_definitions( -DQT_NO_CAST_TO_ASCII ) add_subdirectory( kabc ) add_subdirectory( kcal ) add_subdirectory( kmime ) add_subdirectory( contact ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_QTDBUS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${KDE4_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR}/akonadi/private ) # libakonadi-kde set( akonadikde_LIB_SRC entity.cpp # keep it at top to not break enable-final agentbase.cpp agentfilterproxymodel.cpp agentinstance.cpp agentinstancecreatejob.cpp agentinstancemodel.cpp agentinstancewidget.cpp agentmanager.cpp agentsearchinterface.cpp agenttype.cpp agenttypemodel.cpp agenttypewidget.cpp agenttypedialog.cpp asyncselectionhandler.cpp attribute.cpp attributefactory.cpp cachepolicy.cpp cachepolicypage.cpp changerecorder.cpp collection.cpp collectioncombobox.cpp collectioncopyjob.cpp collectioncreatejob.cpp collectiondeletejob.cpp collectiondialog.cpp collectionfilterproxymodel.cpp collectiongeneralpropertiespage.cpp collectionfetchjob.cpp collectionfetchscope.cpp collectionmodel.cpp collectionmodel_p.cpp collectionmodifyjob.cpp collectionmovejob.cpp collectionpathresolver.cpp collectionpropertiesdialog.cpp collectionpropertiespage.cpp collectionquotaattribute.cpp collectionrequester.cpp collectionrightsattribute.cpp collectionselectjob.cpp collectionstatistics.cpp collectionstatisticsdelegate.cpp collectionstatisticsjob.cpp collectionstatisticsmodel.cpp collectionsync.cpp collectionview.cpp control.cpp dragdropmanager.cpp entitycache.cpp entitydisplayattribute.cpp entityhiddenattribute.cpp entitylistview.cpp entitymimetypefiltermodel.cpp entityrightsfiltermodel.cpp entitytreemodel.cpp entitytreemodel_p.cpp entitytreeview.cpp entitytreeviewstatesaver.cpp erroroverlay.cpp exception.cpp favoritecollectionsmodel.cpp firstrun.cpp flatcollectionproxymodel.cpp item.cpp itemcreatejob.cpp itemcopyjob.cpp itemdeletejob.cpp itemfetchjob.cpp itemfetchscope.cpp itemmodel.cpp itemmonitor.cpp itemmovejob.cpp itemsearchjob.cpp itemserializer.cpp itemserializerplugin.cpp itemmodifyjob.cpp itemsync.cpp itemview.cpp job.cpp - kdescendantsproxymodel.cpp kjobprivatebase.cpp krecursivefilterproxymodel.cpp linkjob.cpp mimetypechecker.cpp monitor.cpp monitor_p.cpp partfetcher.cpp pastehelper.cpp persistentsearchattribute.cpp preprocessorbase.cpp preprocessorbase_p.cpp protocolhelper.cpp progressspinnerdelegate.cpp resourcebase.cpp resourcescheduler.cpp resourceselectjob.cpp resourcesynchronizationjob.cpp searchcreatejob.cpp selectionproxymodel.cpp selftestdialog.cpp session.cpp servermanager.cpp specialcollectionattribute.cpp specialcollections.cpp specialcollectionshelperjobs.cpp specialcollectionsrequestjob.cpp standardactionmanager.cpp statisticsproxymodel.cpp subscriptionjob.cpp subscriptionchangeproxymodel.cpp subscriptiondialog.cpp subscriptionmodel.cpp transactionjobs.cpp transactionsequence.cpp transportresourcebase.cpp typepluginloader.cpp unlinkjob.cpp # Temporary until ported to Qt-plugin framework pluginloader.cpp ) # DBus interfaces and adaptors set(akonadi_xml ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.NotificationManager.xml) set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessage_p.h") qt4_add_dbus_interface( akonadikde_LIB_SRC ${akonadi_xml} notificationmanagerinterface ) qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.AgentManager.xml ) qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Tracer.xml ) qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Control.xml ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Resource.xml resourcebase.h Akonadi::ResourceBase resourceadaptor Akonadi__ResourceAdaptor ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Preprocessor.xml preprocessorbase_p.h Akonadi::PreprocessorBasePrivate preprocessoradaptor Akonadi__PreprocessorAdaptor ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Status.xml agentbase.h Akonadi::AgentBase statusadaptor Akonadi__StatusAdaptor ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Control.xml agentbase.h Akonadi::AgentBase controladaptor Akonadi__ControlAdaptor) qt4_add_dbus_adaptor( akonadikde_LIB_SRC interfaces/org.freedesktop.Akonadi.Resource.Transport.xml transportresourcebase_p.h Akonadi::TransportResourceBasePrivate transportadaptor Akonadi__TransportAdaptor ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC interfaces/org.freedesktop.Akonadi.Agent.Search.xml agentsearchinterface_p.h Akonadi::AgentSearchInterfacePrivate searchadaptor Akonadi__SearchAdaptor ) kde4_add_ui_files( akonadikde_LIB_SRC cachepolicypage.ui collectiongeneralpropertiespage.ui subscriptiondialog.ui controlprogressindicator.ui selftestdialog.ui erroroverlay.ui ) kde4_add_library( akonadi-kde SHARED ${akonadikde_LIB_SRC} ) macro_ensure_version( "4.2.0" ${KDE_VERSION} KDE_IS_AT_LEAST_42 ) target_link_libraries( akonadi-kde ${KDE4_SOLID_LIBS} ${QT_QTNETWORK_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTSQL_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${AKONADI_COMMON_LIBRARIES} ) set( AKONADI_KDE_DEPS ${KDE4_KDEUI_LIBS} ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} ) if(KDE_IS_AT_LEAST_42) target_link_libraries( akonadi-kde LINK_INTERFACE_LIBRARIES ${AKONADI_KDE_DEPS}) else(KDE_IS_AT_LEAST_42) target_link_libraries( akonadi-kde ${AKONADI_KDE_DEPS}) endif(KDE_IS_AT_LEAST_42) set_target_properties( akonadi-kde PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install( TARGETS akonadi-kde EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS} ) ########### install files ############### install( FILES akonadi_export.h agentbase.h agentfilterproxymodel.h agentinstance.h agentinstancecreatejob.h agentinstancemodel.h agentinstancewidget.h agentmanager.h agentsearchinterface.h agenttype.h agenttypemodel.h agenttypewidget.h agenttypedialog.h attribute.h attributefactory.h cachepolicy.h changerecorder.h collection.h collectioncombobox.h collectioncopyjob.h collectioncreatejob.h collectiondeletejob.h collectiondialog.h collectionfilterproxymodel.h collectionfetchjob.h collectionfetchscope.h collectionmodel.h collectionmodifyjob.h collectionmovejob.h collectionpropertiesdialog.h collectionpropertiespage.h collectionquotaattribute.h collectionrequester.h collectionstatisticsdelegate.h collectionstatisticsmodel.h collectionstatistics.h collectionstatisticsjob.h collectionview.h control.h entity.h entitydisplayattribute.h entityhiddenattribute.h entitylistview.h entitymimetypefiltermodel.h entitytreemodel.h entitytreeview.h entitytreeviewstatesaver.h exception.h favoritecollectionsmodel.h item.h itemcreatejob.h itemcopyjob.h itemdeletejob.h itemfetchjob.h itemfetchscope.h itemmodel.h itemmodifyjob.h itemmonitor.h itemmovejob.h itempayloadinternals_p.h itemsearchjob.h itemserializerplugin.h itemsync.h itemview.h job.h linkjob.h mimetypechecker.h monitor.h partfetcher.h persistentsearchattribute.h preprocessorbase.h qtest_akonadi.h resourcebase.h resourcesynchronizationjob.h searchcreatejob.h selectionproxymodel.h session.h servermanager.h specialcollections.h specialcollectionsrequestjob.h standardactionmanager.h statisticsproxymodel.h transactionjobs.h transactionsequence.h transportresourcebase.h unlinkjob.h DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi COMPONENT Devel ) install( FILES collectionpathresolver_p.h DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi/private COMPONENT Devel ) install( FILES kcfg2dbus.xsl DESTINATION ${DATA_INSTALL_DIR}/akonadi-kde ) diff --git a/akonadi/collectioncombobox.cpp b/akonadi/collectioncombobox.cpp index 96b9cb555..afeb8218f 100644 --- a/akonadi/collectioncombobox.cpp +++ b/akonadi/collectioncombobox.cpp @@ -1,164 +1,164 @@ /* This file is part of Akonadi Contact. Copyright (c) 2007-2009 Tobias Koenig 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 "collectioncombobox.h" #include "asyncselectionhandler_p.h" #include #include #include #include #include #include -#include "kdescendantsproxymodel_p.h" +#include #include "collectionutils_p.h" #include using namespace Akonadi; class CollectionComboBox::Private { public: Private( QAbstractItemModel *customModel, CollectionComboBox *parent ) : mParent( parent ), mMonitor( 0 ), mModel( 0 ) { QAbstractItemModel *baseModel; if ( customModel ) { baseModel = customModel; } else { mMonitor = new Akonadi::ChangeRecorder( mParent ); mMonitor->fetchCollection( true ); mMonitor->setCollectionMonitored( Akonadi::Collection::root() ); mModel = new EntityTreeModel( mMonitor, mParent ); mModel->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation ); baseModel = mModel; } KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( parent ); proxyModel->setDisplayAncestorData( true ); proxyModel->setSourceModel( baseModel ); mMimeTypeFilterModel = new CollectionFilterProxyModel( parent ); mMimeTypeFilterModel->setSourceModel( proxyModel ); mRightsFilterModel = new EntityRightsFilterModel( parent ); mRightsFilterModel->setSourceModel( mMimeTypeFilterModel ); mParent->setModel( mRightsFilterModel ); mSelectionHandler = new AsyncSelectionHandler( mRightsFilterModel, mParent ); mParent->connect( mSelectionHandler, SIGNAL( collectionAvailable( const QModelIndex& ) ), mParent, SLOT( activated( const QModelIndex& ) ) ); mParent->connect( mParent, SIGNAL( activated( int ) ), mParent, SLOT( activated( int ) ) ); } ~Private() { } void activated( int index ); void activated( const QModelIndex& index ); CollectionComboBox *mParent; ChangeRecorder *mMonitor; EntityTreeModel *mModel; CollectionFilterProxyModel *mMimeTypeFilterModel; EntityRightsFilterModel *mRightsFilterModel; AsyncSelectionHandler *mSelectionHandler; }; void CollectionComboBox::Private::activated( int index ) { const QModelIndex modelIndex = mParent->model()->index( index, 0 ); if ( modelIndex.isValid() ) emit mParent->currentChanged( modelIndex.data( EntityTreeModel::CollectionRole).value() ); } void CollectionComboBox::Private::activated( const QModelIndex &index ) { mParent->setCurrentIndex( index.row() ); } CollectionComboBox::CollectionComboBox( QWidget *parent ) : KComboBox( parent ), d( new Private( 0, this ) ) { } CollectionComboBox::CollectionComboBox( QAbstractItemModel *model, QWidget *parent ) : KComboBox( parent ), d( new Private( model, this ) ) { } CollectionComboBox::~CollectionComboBox() { delete d; } void CollectionComboBox::setMimeTypeFilter( const QStringList &contentMimeTypes ) { d->mMimeTypeFilterModel->clearFilters(); d->mMimeTypeFilterModel->addMimeTypeFilters( contentMimeTypes ); if ( d->mMonitor ) foreach ( const QString &mimeType, contentMimeTypes ) d->mMonitor->setMimeTypeMonitored( mimeType, true ); } QStringList CollectionComboBox::mimeTypeFilter() const { return d->mMimeTypeFilterModel->mimeTypeFilters(); } void CollectionComboBox::setAccessRightsFilter( Collection::Rights rights ) { d->mRightsFilterModel->setAccessRights( rights ); } Collection::Rights CollectionComboBox::accessRightsFilter() const { return d->mRightsFilterModel->accessRights(); } void CollectionComboBox::setDefaultCollection( const Collection &collection ) { d->mSelectionHandler->waitForCollection( collection ); } Akonadi::Collection CollectionComboBox::currentCollection() const { const QModelIndex modelIndex = model()->index( currentIndex(), 0 ); if ( modelIndex.isValid() ) return modelIndex.data( Akonadi::EntityTreeModel::CollectionRole ).value(); else return Akonadi::Collection(); } #include "collectioncombobox.moc" diff --git a/akonadi/contact/CMakeLists.txt b/akonadi/contact/CMakeLists.txt index 6b618b4e6..7a3766785 100644 --- a/akonadi/contact/CMakeLists.txt +++ b/akonadi/contact/CMakeLists.txt @@ -1,150 +1,149 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/kabc ${SOPRANO_INCLUDE_DIR} ) add_subdirectory(tests) add_subdirectory(kcm) add_subdirectory(editor/im) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII ${KDE4_ENABLE_EXCEPTIONS}") ########### next target ############### set(akonadicontact_actions_SRCS actions/dialphonenumberaction.cpp actions/showaddressaction.cpp actions/qskypedialer.cpp ) kde4_add_kcfg_files(akonadicontact_actions_SRCS actions/contactactionssettings.kcfgc) set(akonadicontact_editor_SRCS editor/addresseditwidget.cpp editor/categorieseditwidget.cpp editor/contacteditorwidget.cpp editor/customfieldeditordialog.cpp editor/customfieldsdelegate.cpp editor/customfieldseditwidget.cpp editor/customfieldsmodel.cpp editor/dateeditwidget.cpp editor/displaynameeditwidget.cpp editor/emaileditwidget.cpp editor/freebusyeditwidget.cpp editor/geoeditwidget.cpp editor/im/imdelegate.cpp editor/im/imeditordialog.cpp editor/im/immodel.cpp editor/im/improtocols.cpp editor/imagewidget.cpp editor/imeditwidget.cpp editor/kdatepickerpopup.cpp editor/kedittagsdialog.cpp editor/nameeditdialog.cpp editor/nameeditwidget.cpp editor/phoneeditwidget.cpp editor/secrecyeditwidget.cpp editor/soundeditwidget.cpp editor/tagwidget.cpp ) set(akonadicontact_LIB_SRC abstractcontactformatter.cpp attributeregistrar.cpp collectionfiltermodel.cpp - ../kdescendantsproxymodel.cpp contactcompletionmodel.cpp contactdefaultactions.cpp contacteditor.cpp contacteditordialog.cpp contactgroupeditor.cpp contactgroupeditordelegate.cpp contactgroupeditordialog.cpp contactgroupexpandjob.cpp contactgrouplineedit.cpp contactgroupmodel.cpp contactgroupsearchjob.cpp contactgroupviewer.cpp contactgroupviewerdialog.cpp contactmetadata.cpp contactmetadataattribute.cpp contactsearchjob.cpp contactsfilterproxymodel.cpp contactstreemodel.cpp contactviewer.cpp contactviewerdialog.cpp customfields.cpp customfieldmanager.cpp emailaddressselection.cpp emailaddressselectiondialog.cpp emailaddressselectionproxymodel.cpp emailaddressselectionwidget.cpp leafextensionproxymodel.cpp recentcontactscollections.cpp recentcontactscollectionrequestjob.cpp standardcontactformatter.cpp waitingoverlay.cpp ${akonadicontact_actions_SRCS} ${akonadicontact_editor_SRCS} ) qt4_wrap_ui(akonadicontact_LIB_SRC contactgroupeditor.ui) kde4_add_kcfg_files(akonadicontact_LIB_SRC recentcontactscollectionssettings.kcfgc ) kde4_add_library(akonadi-contact SHARED ${akonadicontact_LIB_SRC}) target_link_libraries(akonadi-contact akonadi-kde kabc kcal kmime kpimutils ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBS} ${NEPOMUK_LIBRARIES}) target_link_libraries(akonadi-contact LINK_INTERFACE_LIBRARIES akonadi-kde kabc kcal kmime kpimutils ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBS} ${NEPOMUK_LIBRARIES}) set_target_properties(akonadi-contact PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION}) install(TARGETS akonadi-contact EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES editor/pics/world.jpg DESTINATION ${DATA_INSTALL_DIR}/akonadi/contact/pics) install(FILES editor/data/zone.tab DESTINATION ${DATA_INSTALL_DIR}/akonadi/contact/data) install(FILES recentcontactscollections.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) install( FILES abstractcontactformatter.h akonadi-contact_export.h contactdefaultactions.h contacteditor.h contacteditordialog.h contacteditorpageplugin.h contactgroupeditor.h contactgroupeditordialog.h contactgroupexpandjob.h contactgroupsearchjob.h contactgroupviewer.h contactgroupviewerdialog.h contactsearchjob.h contactsfilterproxymodel.h contactstreemodel.h contactviewer.h contactviewerdialog.h emailaddressselection.h emailaddressselectiondialog.h emailaddressselectionwidget.h recentcontactscollectionrequestjob.h standardcontactformatter.h DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi/contact COMPONENT Devel ) diff --git a/akonadi/kbihash_p.h b/akonadi/kbihash_p.h deleted file mode 100644 index bfc107454..000000000 --- a/akonadi/kbihash_p.h +++ /dev/null @@ -1,567 +0,0 @@ -/* - - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - 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 KBIHASH_P_H -#define KBIHASH_P_H - -#include -#include - -#include - -template -class KBiAssociativeContainer; - -template -QDebug operator<<(QDebug out, const KBiAssociativeContainer &container); - -template -QDataStream &operator<<(QDataStream &out, const KBiAssociativeContainer &container); - -template -QDataStream &operator>>(QDataStream &in, KBiAssociativeContainer &container); - - -template -class KBiAssociativeContainer -{ - // We need to convert from a QHash::iterator or QMap::iterator - // to a KBiAssociativeContainer::iterator (left or right) - // Do do that we use this implicit ctor. We partially specialize - // it for QHash and QMap types. - // Our iterator inherits from this struct to get the implicit ctor, - // and this struct must inherit from the QHash or QMap iterator. - template - struct _iterator_impl_ctor : public Container::iterator - { - _iterator_impl_ctor(typename Container::iterator it); - }; - - template - struct _iterator_impl_ctor, T, U> : public QHash::iterator - { - /* implicit */ _iterator_impl_ctor(const typename QHash::iterator it) - // Using internals here because I was too lazy to write my own iterator. - : QHash::iterator(reinterpret_cast(static_cast *>(it))) - { - - } - }; - - template - struct _iterator_impl_ctor, T, U> : public QMap::iterator - { - /* implicit */ _iterator_impl_ctor(const typename QMap::iterator it) - // Using internals here because I was too lazy to write my own iterator. - : QMap::iterator(static_cast(it)) - { - - } - }; -public: - typedef typename RightContainer::mapped_type left_type; - typedef typename LeftContainer::mapped_type right_type; - - template - class _iterator : public _iterator_impl_ctor - { - public: - explicit inline _iterator(void *data) : Container::iterator(data) {} - - /* implicit */ _iterator(const typename Container::iterator it) - : _iterator_impl_ctor(it) - { - - } - - inline const typename Container::mapped_type &value() const { - return Container::iterator::value(); - } - inline const typename Container::mapped_type &operator*() const { - return Container::iterator::operator*(); - } - inline const typename Container::mapped_type *operator->() const { - return Container::iterator::operator->(); - } - - private: -#ifndef Q_CC_MSVC - using Container::iterator::operator*; - using Container::iterator::operator->; - using Container::iterator::value; -#endif - }; - - typedef _iterator left_iterator; - typedef typename LeftContainer::const_iterator left_const_iterator; - typedef _iterator right_iterator; - typedef typename RightContainer::const_iterator right_const_iterator; - - inline KBiAssociativeContainer() {} - inline KBiAssociativeContainer(const KBiAssociativeContainer &other) { - *this = other; - } - - const KBiAssociativeContainer &operator=(const KBiAssociativeContainer &other) { - _leftToRight = other._leftToRight; _rightToLeft = other._rightToLeft; return *this; - } - - inline bool removeLeft(left_type t) { - const right_type u = _leftToRight.take(t); - return _rightToLeft.remove(u) != 0; - } - - inline bool removeRight(right_type u) { - const left_type t = _rightToLeft.take(u); - return _leftToRight.remove(t) != 0; - } - - inline right_type takeLeft(left_type t) { - const right_type u = _leftToRight.take(t); - _rightToLeft.remove(u); - return u; - } - - inline left_type takeRight(right_type u) { - const left_type t = _rightToLeft.take(u); - _leftToRight.remove(t); - return t; - } - - inline left_type rightToLeft(right_type u) const { - return _rightToLeft.value(u); - } - - inline right_type leftToRight(left_type t) const { - return _leftToRight.value(t); - } - - inline bool leftContains(left_type t) const { - return _leftToRight.contains(t); - } - - inline bool rightContains(right_type u) const { - return _rightToLeft.contains(u); - } - - inline int size() const { - return _leftToRight.size(); - } - - inline int count() const { - return _leftToRight.count(); - } - - inline int capacity() const { - return _leftToRight.capacity(); - } - - void reserve(int size) { - _leftToRight.reserve(size); _rightToLeft.reserve(size); - } - - inline void squeeze() { - _leftToRight.squeeze(); _rightToLeft.squeeze(); - } - - inline void detach() { - _leftToRight.detach(); _rightToLeft.detach(); - } - - inline bool isDetached() const { - return _leftToRight.isDetached(); - } - - inline void setSharable(bool sharable) { - _leftToRight.setSharable(sharable); _rightToLeft.setSharable(sharable); - } - - inline bool isSharedWith(const KBiAssociativeContainer &other) const { - return _leftToRight.isSharedWith(other._leftToRight) && _rightToLeft.isSharedWith(other._leftToRight); - } - - void clear() { - _leftToRight.clear(); _rightToLeft.clear(); - } - - QList leftValues() const { - return _leftToRight.keys(); - } - - QList rightValues() const { - return _rightToLeft.keys(); - } - - right_iterator eraseRight(right_iterator it) { - Q_ASSERT(it != rightEnd()); - _leftToRight.remove(it.value()); - return _rightToLeft.erase(it); - } - - left_iterator eraseLeft(left_iterator it) { - Q_ASSERT(it != leftEnd()); - _rightToLeft.remove(it.value()); - return _leftToRight.erase(it); - } - - left_iterator findLeft(left_type t) { - return _leftToRight.find(t); - } - - left_const_iterator findLeft(left_type t) const { - return _leftToRight.find(t); - } - - left_const_iterator constFindLeft(left_type t) const { - return _leftToRight.constFind(t); - } - - right_iterator findRight(right_type u) { - return _rightToLeft.find(u); - } - - right_const_iterator findRight(right_type u) const { - return _rightToLeft.find(u); - } - - right_const_iterator constFindRight(right_type u) const { - return _rightToLeft.find(u); - } - - left_iterator insert(left_type t, right_type u) { - // biHash.insert(5, 7); // creates 5->7 in _leftToRight and 7->5 in _rightToLeft - // biHash.insert(5, 9); // replaces 5->7 with 5->9 in _leftToRight and inserts 9->5 in _rightToLeft. - // The 7->5 in _rightToLeft would be dangling, so we remove it before insertion. - - // This means we need to hash u and t up to twice each. Could probably be done better using QHashNode. - - if (_leftToRight.contains(t)) - _rightToLeft.remove(_leftToRight.take(t)); - if (_rightToLeft.contains(u)) - _leftToRight.remove(_rightToLeft.take(u)); - - _rightToLeft.insert(u, t); - return _leftToRight.insert(t, u); - } - - - KBiAssociativeContainer &intersect(const KBiAssociativeContainer &other) { - typename KBiAssociativeContainer::left_iterator it = leftBegin(); - while (it != leftEnd()) { - if (!other.leftContains(it.key())) - it = eraseLeft(it); - else - ++it; - } - return *this; - } - - KBiAssociativeContainer &subtract(const KBiAssociativeContainer &other) { - typename KBiAssociativeContainer::left_iterator it = leftBegin(); - while (it != leftEnd()) { - if (other._leftToRight.contains(it.key())) - it = eraseLeft(it); - else - ++it; - } - return *this; - } - - KBiAssociativeContainer &unite(const KBiAssociativeContainer &other) { - typename LeftContainer::const_iterator it = other._leftToRight.constBegin(); - const typename LeftContainer::const_iterator end = other._leftToRight.constEnd(); - while (it != end) { - const left_type key = it.key(); - if (!_leftToRight.contains(key)) - insert(key, it.value()); - ++it; - } - return *this; - } - - void updateRight(left_iterator it, right_type u) { - Q_ASSERT(it != leftEnd()); - const left_type key = it.key(); - _rightToLeft.remove(_leftToRight.value(key)); - _leftToRight[key] = u; - _rightToLeft[u] = key; - } - - void updateLeft(right_iterator it, left_type t) { - Q_ASSERT(it != rightEnd()); - const right_type key = it.key(); - _leftToRight.remove(_rightToLeft.value(key)); - _rightToLeft[key] = t; - _leftToRight[t] = key; - } - - inline bool isEmpty() const { - return _leftToRight.isEmpty(); - } - - const right_type operator[](const left_type &t) const { - return _leftToRight.operator[](t); - } - - bool operator==(const KBiAssociativeContainer &other) { - return _leftToRight.operator == (other._leftToRight); - } - - bool operator!=(const KBiAssociativeContainer &other) { - return _leftToRight.operator != (other._leftToRight); - } - - left_iterator toLeftIterator(right_iterator it) const { - Q_ASSERT(it != rightEnd()); - return _leftToRight.find(it.value()); - } - - right_iterator toRightIterator(left_iterator it) const { - Q_ASSERT(it != leftEnd()); - return _rightToLeft.find(it.value()); - } - - inline left_iterator leftBegin() { - return _leftToRight.begin(); - } - - inline left_iterator leftEnd() { - return _leftToRight.end(); - } - - inline left_const_iterator leftBegin() const { - return _leftToRight.begin(); - } - - inline left_const_iterator leftEnd() const { - return _leftToRight.end(); - } - - inline left_const_iterator leftConstBegin() const { - return _leftToRight.constBegin(); - } - - inline left_const_iterator leftConstEnd() const { - return _leftToRight.constEnd(); - } - - inline right_iterator rightBegin() { - return _rightToLeft.begin(); - } - - inline right_iterator rightEnd() { - return _rightToLeft.end(); - } - - inline right_const_iterator rightBegin() const { - return _rightToLeft.begin(); - } - - inline right_const_iterator rightEnd() const { - return _rightToLeft.end(); - } - inline right_const_iterator rightConstBegin() const { - return _rightToLeft.constBegin(); - } - - inline right_const_iterator rightConstEnd() const { - return _rightToLeft.constEnd(); - } - - static KBiAssociativeContainer fromHash(const QHash &hash) { - KBiAssociativeContainer container; - typename QHash::const_iterator it = hash.constBegin(); - const typename QHash::const_iterator end = hash.constEnd(); - for ( ; it != end; ++it) - container.insert(it.key(), it.value()); - return container; - } - - static KBiAssociativeContainer fromMap(const QMap &hash) { - KBiAssociativeContainer container; - typename QMap::const_iterator it = hash.constBegin(); - const typename QMap::const_iterator end = hash.constEnd(); - for ( ; it != end; ++it) - container.insert(it.key(), it.value()); - return container; - } - - friend QDataStream &operator<< (QDataStream &out, const KBiAssociativeContainer &bihash); - friend QDataStream &operator>> (QDataStream &in, KBiAssociativeContainer &biHash); - friend QDebug operator<< (QDebug out, const KBiAssociativeContainer &biHash); -protected: - LeftContainer _leftToRight; - RightContainer _rightToLeft; -}; - -template -QDataStream &operator<<(QDataStream &out, const KBiAssociativeContainer &container) -{ - return out << container._leftToRight; -} - -template -QDataStream &operator>>(QDataStream &in, KBiAssociativeContainer &container) -{ - LeftContainer leftToRight; - in >> leftToRight; - typename LeftContainer::const_iterator it = leftToRight.constBegin(); - const typename LeftContainer::const_iterator end = leftToRight.constEnd(); - for (; it != end; ++it) - container.insert(it.key(), it.value()); - - return in; -} - -template -struct _containerType -{ - operator const char *(); -}; - -template -struct _containerType, T, U> -{ - operator const char *() - { - return "QHash"; - } -}; - -template -struct _containerType, T, U> -{ - operator const char *() - { - return "QMap"; - } -}; - - -template -static const char * containerType() -{ - return _containerType(); -} - -template -QDebug operator<<(QDebug out, const KBiAssociativeContainer &container) -{ - typename KBiAssociativeContainer::left_const_iterator it = container.leftConstBegin(); - - const typename KBiAssociativeContainer::left_const_iterator end = container.leftConstEnd(); - out.nospace() << "KBiAssociativeContainer<" << containerType() << ", " << containerType() << ">" << "("; - for (; it != end; ++it) - out << "(" << it.key() << " <=> " << it.value() << ") "; - - out << ")"; - return out; -} - -/** - * @brief KBiHash provides a bi-directional hash container - * - * @note This class is designed to make mapping easier in proxy model implementations. - * - * @todo Figure out whether to discard this and use boost::bimap instead, submit it Qt or keep it here and make more direct use of QHashNode. - */ -template -struct KBiHash : public KBiAssociativeContainer, QHash > -{ - KBiHash() - : KBiAssociativeContainer, QHash > () - { - - } - - KBiHash(const KBiAssociativeContainer, QHash > &container) - : KBiAssociativeContainer, QHash > (container) - { - - } -}; - -template -QDebug operator<<(QDebug out, const KBiHash &biHash) -{ - typename KBiHash::left_const_iterator it = biHash.leftConstBegin(); - - const typename KBiHash::left_const_iterator end = biHash.leftConstEnd(); - out.nospace() << "KBiHash("; - for (; it != end; ++it) - out << "(" << it.key() << " <=> " << it.value() << ") "; - - out << ")"; - return out; -} - -template -struct KHash2Map : public KBiAssociativeContainer, QMap > -{ - KHash2Map() - : KBiAssociativeContainer, QMap > () - { - - } - - KHash2Map(const KBiAssociativeContainer, QMap > &container) - : KBiAssociativeContainer, QMap > (container) - { - - } - - typename KBiAssociativeContainer, QMap >::right_iterator rightLowerBound(const U &key) - { - return this->_rightToLeft.lowerBound(key); - } - - typename KBiAssociativeContainer, QMap >::right_const_iterator rightLowerBound(const U &key) const - { - return this->_rightToLeft.lowerBound(key); - } - - typename KBiAssociativeContainer, QMap >::right_iterator rightUpperBound(const U &key) - { - return this->_rightToLeft.upperBound(key); - } - - typename KBiAssociativeContainer, QMap >::right_const_iterator rightUpperBound(const U &key) const - { - return this->_rightToLeft.upperBound(key); - } -}; - -template -QDebug operator<<(QDebug out, const KHash2Map &container) -{ - typename KHash2Map::left_const_iterator it = container.leftConstBegin(); - - const typename KHash2Map::left_const_iterator end = container.leftConstEnd(); - out.nospace() << "KHash2Map("; - for (; it != end; ++it) - out << "(" << it.key() << " <=> " << it.value() << ") "; - - out << ")"; - return out; -} - -#endif diff --git a/akonadi/kdescendantsproxymodel.cpp b/akonadi/kdescendantsproxymodel.cpp deleted file mode 100644 index ac638c5f5..000000000 --- a/akonadi/kdescendantsproxymodel.cpp +++ /dev/null @@ -1,922 +0,0 @@ -/* - Copyright (c) 2009 Stephen Kelly - - 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 "kdescendantsproxymodel_p.h" - -#include "kdebug.h" - -#include - -/** - @internal - - Private implementation of DescendantsProxyModel. -*/ -class KDescendantsProxyModelPrivate -{ - public: - - KDescendantsProxyModelPrivate(KDescendantsProxyModel *model) - : q_ptr(model), - m_displayAncestorData( false ), - m_ancestorSeparator( QLatin1String( " / " ) ) - { - } - - Q_DECLARE_PUBLIC( KDescendantsProxyModel ) - KDescendantsProxyModel *q_ptr; - /** - @internal - - Returns the @p row -th descendant of sourceParent. - - For example, if the source model looks like: - @code - -> Item 0-0 (this is row-depth) - -> -> Item 0-1 - -> -> Item 1-1 - -> -> -> Item 0-2 - -> -> -> Item 1-2 - -> Item 1-0 - @endcode - - Then findSourceIndexForRow(3, index(Item 0-0)) will return an index for Item 1-2 - - @returns The model index in the source model. - - */ - QModelIndex findSourceIndexForRow( int row, QModelIndex sourceParent) const; - - void processPendingParents() { - - } - - /** - @internal - - Returns true if @p sourceIndex has a ancestor that is m_rootDescendIndex. - Note that isDescended(m_rootDescendIndex) is false; - @param sourceIndex The index in the source model. - @returns Whether sourceIndex is an ancestor of rootIndex - */ - bool isDescended(const QModelIndex &sourceIndex) const; - - /** - @internal - - Returns the number of descendants below @p sourceIndex. - - For example, if the source model looks like: - @code - -> Item 0-0 (this is row-depth) - -> -> Item 0-1 - -> -> Item 1-1 - -> -> -> Item 0-2 - -> -> -> Item 1-2 - -> Item 1-0 - @endcode - - The descendant count of the rootIndex would be 6, - of Item 0-0 would be 4, - of Item 1-1 would be 2, - of Item 1-2 would be 0 - etc. - - */ - int descendantCount(const QModelIndex &sourceIndex, int ignoreTerminals=ObserveTerminals) const; - - enum TerminalIgnorance - { - ObserveTerminals, - IgnoreTerminals - }; - - /** - @internal - - Returns the row of @p sourceIndex below the rootDescendIndex. - - For example, if the source model looks like: - @code - -> Item 0-0 (this is row-depth) - -> -> Item 0-1 - -> -> Item 1-1 - -> -> -> Item 0-2 - -> -> -> Item 1-2 - -> Item 1-0 - @endcode - - Then descendedRow(index(Item 0-0) would be 0, - descendedRow(index(Item 0-1) would be 1, - descendedRow(index(Item 0-2) would be 3, - descendedRow(index(Item 1-0) would be 5 - etc. - - @returns The row in the proxy model where @p sourceIndex is represented. - - */ - int descendedRow(const QModelIndex &sourceIndex) const; - - QModelIndexList matchDescendants(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags, int until, const bool matchAll) const; - - enum Operation - { - InsertOperation, - RemoveOperation - }; - - void insertOrRemoveRows(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, int type); - - void sourceRowsAboutToBeInserted(const QModelIndex &, int start, int end); - void sourceRowsInserted(const QModelIndex &, int start, int end); - void sourceRowsAboutToBeRemoved(const QModelIndex &, int start, int end); - void sourceRowsRemoved(const QModelIndex &, int start, int end); - void sourceRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destParent, int destRow); - void sourceRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destParent, int destRow); - void sourceModelAboutToBeReset(); - void sourceModelReset(); - void sourceLayoutAboutToBeChanged(); - void sourceLayoutChanged(); - void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); - void sourceModelDestroyed(); - - QPersistentModelIndex m_rootDescendIndex; - // Hmm, if I make this QHash instead then moves are - // automatically handled. Nope, they're not. deeper levels than base would - // still need to be updated or calculated. - - mutable QHash m_descendantsCount; - - bool m_displayAncestorData; - QString m_ancestorSeparator; - - QList m_terminalIndexes; - void descendNewIndexes(); - - QList m_layoutChangePersistentIndexes; - QModelIndexList m_proxyIndexes; - -}; - -KDescendantsProxyModel::KDescendantsProxyModel( QObject *parent ) - : QAbstractProxyModel( parent ), - d_ptr( new KDescendantsProxyModelPrivate(this) ) -{ - Q_D(KDescendantsProxyModel); - - d->m_rootDescendIndex = QModelIndex(); -} - -void KDescendantsProxyModel::setRootIndex(const QModelIndex &index) -{ - Q_D(KDescendantsProxyModel); - - if (index.isValid()) - Q_ASSERT(index.model() == sourceModel()); - - d->m_rootDescendIndex = index; - d->m_descendantsCount.clear(); - reset(); -} - -KDescendantsProxyModel::~KDescendantsProxyModel() -{ - Q_D(KDescendantsProxyModel); - d->m_descendantsCount.clear(); - delete d_ptr; -} - -QModelIndex KDescendantsProxyModelPrivate::findSourceIndexForRow( int row, QModelIndex idx ) const -{ - Q_Q( const KDescendantsProxyModel ); - int childCount = q->sourceModel()->rowCount(idx); - for (int childRow = 0; childRow < childCount; childRow++) - { - QModelIndex childIndex = q->sourceModel()->index(childRow, 0, idx); - if (row == 0) - { - return childIndex; - } - row--; - if (q->sourceModel()->hasChildren(childIndex)) - { - int childDesc = descendantCount(childIndex); - if (childDesc > row) - { - return findSourceIndexForRow(row, childIndex); - } - row -= childDesc; - } - } - - // This should probably never happen if you use descendantCount before calling this method. - return QModelIndex(); -} - -void KDescendantsProxyModel::setSourceModel(QAbstractItemModel * sourceModel) -{ - Q_D(KDescendantsProxyModel); - - disconnect( sourceModel, SIGNAL(modelReset()), this, SLOT( sourceModelReset() ) ); - disconnect( sourceModel, SIGNAL(modelAboutToBeReset()), this, SLOT(sourceModelAboutToBeReset() ) ); - disconnect( sourceModel, SIGNAL(layoutChanged()), this, SLOT(sourceLayoutChanged()) ); - disconnect( sourceModel, SIGNAL(layoutAboutToBeChanged()), this, SLOT(sourceLayoutAboutToBeChanged()) ); - disconnect( sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex & ) ) ); - disconnect( sourceModel, SIGNAL(rowsInserted(const QModelIndex, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex, int, int)) ); - disconnect( sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex, int, int)), - this, SLOT(sourceRowsAboutToBeInserted(const QModelIndex, int, int)) ); - disconnect( sourceModel, SIGNAL(rowsRemoved(const QModelIndex, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex, int, int)) ); - disconnect( sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex, int, int)), - this, SLOT(sourceRowsAboutToBeRemoved(const QModelIndex, int, int)) ); - disconnect( sourceModel, SIGNAL(rowsMoved(const QModelIndex, int, int, const QModelIndex, int)), - this, SLOT(sourceRowsMoved(const QModelIndex, int, int, const QModelIndex, int)) ); - disconnect( sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex, int, int, const QModelIndex, int)), - this, SLOT(sourceRowsAboutToBeMoved(const QModelIndex, int, int, const QModelIndex, int) ) ); - - QAbstractProxyModel::setSourceModel( sourceModel ); - connect( sourceModel, SIGNAL(modelReset()), SLOT( sourceModelReset() ) ); - connect( sourceModel, SIGNAL(modelAboutToBeReset()), SLOT(sourceModelAboutToBeReset() ) ); - connect( sourceModel, SIGNAL(layoutChanged()), SLOT(sourceLayoutChanged()) ); - connect( sourceModel, SIGNAL(layoutAboutToBeChanged()), SLOT(sourceLayoutAboutToBeChanged()) ); - connect( sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex & ) ) ); - connect( sourceModel, SIGNAL(rowsInserted(const QModelIndex, int, int)), - SLOT(sourceRowsInserted(const QModelIndex, int, int)) ); - connect( sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex, int, int)), - SLOT(sourceRowsAboutToBeInserted(const QModelIndex, int, int)) ); - connect( sourceModel, SIGNAL(rowsRemoved(const QModelIndex, int, int)), - SLOT(sourceRowsRemoved(const QModelIndex, int, int)) ); - connect( sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex, int, int)), - SLOT(sourceRowsAboutToBeRemoved(const QModelIndex, int, int)) ); - connect( sourceModel, SIGNAL(rowsMoved(const QModelIndex, int, int, const QModelIndex, int)), - SLOT(sourceRowsMoved(const QModelIndex, int, int, const QModelIndex, int)) ); - connect( sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex, int, int, const QModelIndex, int)), - SLOT(sourceRowsAboutToBeMoved(const QModelIndex, int, int, const QModelIndex, int) ) ); - - d->m_descendantsCount.clear(); - reset(); -} - -bool KDescendantsProxyModelPrivate::isDescended(const QModelIndex &sourceIndex) const -{ - Q_Q(const KDescendantsProxyModel); - - if (sourceIndex == m_rootDescendIndex) - { - return false; - } - - QModelIndex parentIndex = q->sourceModel()->parent(sourceIndex); - - if (parentIndex == m_rootDescendIndex) - { - return true; - } - bool found = false; - - forever - { - parentIndex = parentIndex.parent(); - if (parentIndex == m_rootDescendIndex) - { - found = true; - break; - } - if (!parentIndex.isValid()) - break; - } - return found; -} - -int KDescendantsProxyModelPrivate::descendedRow(const QModelIndex &sourceIndex) const -{ - Q_Q(const KDescendantsProxyModel); - QModelIndex parentIndex = sourceIndex.parent(); - int row = sourceIndex.row(); - - for (int childRow = 0; childRow < sourceIndex.row(); childRow++ ) - { - QModelIndex childIndex = q->sourceModel()->index( childRow, sourceIndex.column(), parentIndex ); - if (q->sourceModel()->hasChildren(childIndex)) - row += descendantCount(childIndex); - } - - if (parentIndex == m_rootDescendIndex) - { - // Return 0 instead of -1 for an invalid index. - if (row < 0) - { - return 0; - } - return row; - } - else if(!parentIndex.isValid()) - { - // Should never happen. - // Someone must have called this with sourceIndex outside of m_rootDescendIndex - return 0; - } - else { - int dr = descendedRow(parentIndex); - return row + dr + 1; - } -} - -QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex & sourceIndex) const -{ - Q_D(const KDescendantsProxyModel); - - if (sourceIndex == d->m_rootDescendIndex) - { - return QModelIndex(); - } - - if ( d->isDescended( sourceIndex ) ) - { - int row = d->descendedRow( sourceIndex ); - if (row < 0) - return QModelIndex(); - return createIndex( row, sourceIndex.column() ); - } else { - return QModelIndex(); - } -} - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelIndex &sourceParentIndex, int start, int end) -{ - insertOrRemoveRows(sourceParentIndex, start, end, InsertOperation); -} - -void KDescendantsProxyModelPrivate::insertOrRemoveRows(const QModelIndex &sourceParentIndex, int start, int end, int operationType) -{ - - Q_Q(KDescendantsProxyModel); - - int c = descendedRow(sourceParentIndex); - -// Can't simply get the descendantCount of sourceModel()->index(start, 0, sourceParent), -// because start might not exist as a child of sourceParent yet. -// Maybe I should special case (!sourceParent.hasChildren) instead. - - // Only the first column can have child items. It is only those we need to count. - const int column = 0; - for (int childRow = 0; childRow < start; childRow++) - { - QModelIndex childIndex = q->sourceModel()->index( childRow, column, sourceParentIndex ); -// kDebug() << childIndex << descendantCount(childIndex); - if (q->sourceModel()->hasChildren(childIndex)) - c += descendantCount(childIndex); - } - -// @code -// -> Item 0-0 (this is row-depth) -// -> -> Item 0-1 -// -> -> Item 1-1 -// -> -> -> Item 0-2 -// -> -> -> Item 1-2 -// -> Item 1-0 -// @endcode -// -// If the sourceModel reports that a row is inserted between Item 0-2 Item 1-2, -// this methods receives a sourceParent of Item 1-1, and a start of 1. -// It has a descendedRow of 2. The proxied start is the number of rows above parent, -// and the start below parent. The parent itself must also be accounted for if it -// is part of the model. - -// Check if it's descended instead? - - int proxy_start = c + start; - int proxy_end = c + end; - - if (isDescended(sourceParentIndex)) - { - proxy_start++; - proxy_end++; - } - - if (operationType == InsertOperation) - q->beginInsertRows(m_rootDescendIndex, proxy_start, proxy_end); - else if (operationType == RemoveOperation) - { - // need to notify that we're also removing the descendants. - for (int childRow = start; childRow <= end; childRow++) - { - QModelIndex childIndex = q->sourceModel()->index(childRow, column, sourceParentIndex); - if (q->sourceModel()->hasChildren(childIndex)) - proxy_end += descendantCount(childIndex); - } - Q_ASSERT( proxy_end <= q->rowCount() ); - q->beginRemoveRows(m_rootDescendIndex, proxy_start, proxy_end); - } -} - -void KDescendantsProxyModelPrivate::sourceRowsInserted(const QModelIndex &sourceParentIndex, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - - m_descendantsCount.clear(); - - // Don't count the descendants of newly inserted indexes until after endInsertRows. - // The reason for this is that at the time we emitted beginInsertRows, we couldn't count the descendants - // of new items (they weren't known to the sourceModel), and now we can. - const int column = 0; - for (int childRow = start; childRow <= end; childRow++) - { - QModelIndex childIndex = q->sourceModel()->index( childRow, column, sourceParentIndex ); - m_terminalIndexes << QPersistentModelIndex(childIndex); - } - - q->endInsertRows(); - descendNewIndexes(); -} - -void KDescendantsProxyModelPrivate::descendNewIndexes() -{ - Q_Q(KDescendantsProxyModel); - - QMutableListIterator i(m_terminalIndexes); - while (i.hasNext()) - { - QModelIndex idx = i.next(); - - int descCount = descendantCount(idx, IgnoreTerminals); - - if (descCount <= 0) - { - i.remove(); - continue; - } - - // if descCount > 0, this is a new index which has new child indexes. - - int proxyStart = descendedRow(idx); - // Need to ignore terminals so we know how many rows will be inserted by removing them. - int proxyEnd = proxyStart + descendantCount(idx, IgnoreTerminals); - - if (isDescended(idx)) - { - proxyStart++; - proxyEnd++; - } - q->beginInsertRows(QModelIndex(), proxyStart, proxyEnd - 1 ); - i.remove(); - m_descendantsCount.clear(); - q->endInsertRows(); - } -} - - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destParent, int destRow) -{ - Q_Q(KDescendantsProxyModel); - int c = descendedRow(parent); - int d = descendedRow(destParent); - - bool allowMove = q->beginMoveRows(QModelIndex(), c+1+start, c+1+end, QModelIndex(), d+1+destRow); - Q_UNUSED(allowMove); - Q_ASSERT(allowMove); -} - -void KDescendantsProxyModelPrivate::sourceRowsMoved(const QModelIndex &sourceParentIndex, int start, int end, const QModelIndex &destParentIndex, int destRow) -{ - Q_Q(KDescendantsProxyModel); - Q_UNUSED(sourceParentIndex); - Q_UNUSED(start); - Q_UNUSED(end); - Q_UNUSED(destParentIndex); - Q_UNUSED(destRow); - - m_descendantsCount.clear(); - - q->endMoveRows(); -} - - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -{ - insertOrRemoveRows(parent, start, end, RemoveOperation); -} - -void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &sourceParentIndex, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - Q_UNUSED(sourceParentIndex); - Q_UNUSED(start); - Q_UNUSED(end); - - m_descendantsCount.clear(); - q->endRemoveRows(); -} - -void KDescendantsProxyModelPrivate::sourceModelAboutToBeReset() -{ - Q_Q(KDescendantsProxyModel); - q->beginResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceModelReset() -{ - Q_Q(KDescendantsProxyModel); - - m_descendantsCount.clear(); - q->endResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceLayoutAboutToBeChanged() -{ - Q_Q(KDescendantsProxyModel); - - emit q->layoutAboutToBeChanged(); - - foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) - { - m_proxyIndexes << proxyPersistentIndex; - m_layoutChangePersistentIndexes << QPersistentModelIndex(q->mapToSource(proxyPersistentIndex)); - } -} - -void KDescendantsProxyModelPrivate::sourceLayoutChanged() -{ - Q_Q(KDescendantsProxyModel); - - for(int i = 0; i < m_proxyIndexes.size(); ++i) - { - q->changePersistentIndex(m_proxyIndexes.at(i), q->mapFromSource(m_layoutChangePersistentIndexes.at(i))); - } - - m_layoutChangePersistentIndexes.clear(); - m_proxyIndexes.clear(); - - m_descendantsCount.clear(); - - emit q->layoutChanged(); -} - -QModelIndex KDescendantsProxyModel::mapToSource(const QModelIndex &proxyIndex) const -{ - Q_D(const KDescendantsProxyModel); - - if (!proxyIndex.isValid()) - return d->m_rootDescendIndex; - - if (proxyIndex.column() >= sourceModel()->columnCount()) - return QModelIndex(); - - QModelIndex idx = d->findSourceIndexForRow( proxyIndex.row(), d->m_rootDescendIndex ); - - if (proxyIndex.column() > 0) - { - return sourceModel()->index(idx.row(), proxyIndex.column(), idx.parent()); - } - return idx; -} - -QVariant KDescendantsProxyModel::data(const QModelIndex & index, int role) const -{ - Q_D(const KDescendantsProxyModel ); - - if (!sourceModel()) - return QVariant(); - - if (!index.isValid()) - return sourceModel()->data(index, role); - - QModelIndex sourceIndex = mapToSource( index ); - - if ((d->m_displayAncestorData) && ( role == Qt::DisplayRole ) ) - { - if (!sourceIndex.isValid()) - { - return QVariant(); - } - QString displayData = sourceIndex.data().toString(); - sourceIndex = sourceIndex.parent(); - while (sourceIndex.isValid()) - { - displayData.prepend(d->m_ancestorSeparator); - displayData.prepend(sourceIndex.data().toString()); - sourceIndex = sourceIndex.parent(); - } - return displayData; - } else { - return sourceIndex.data(role); - } - -} - -QMimeData* KDescendantsProxyModel::mimeData( const QModelIndexList & indexes ) const -{ - Q_ASSERT(sourceModel()); - QModelIndexList sourceIndexes; - foreach(const QModelIndex& index, indexes) - sourceIndexes << mapToSource(index); - return sourceModel()->mimeData(sourceIndexes); -} - -QStringList KDescendantsProxyModel::mimeTypes() const -{ - Q_ASSERT(sourceModel()); - return sourceModel()->mimeTypes(); -} - -bool KDescendantsProxyModel::hasChildren ( const QModelIndex & parent ) const -{ - return rowCount(parent) > 0; -} - -int KDescendantsProxyModel::rowCount(const QModelIndex & proxyIndex) const -{ - Q_D(const KDescendantsProxyModel ); - - if (!sourceModel() || proxyIndex.column() > 0) - return 0; - - QModelIndex sourceIndex = mapToSource(proxyIndex); - - if (sourceIndex == d->m_rootDescendIndex) - { - int c = d->descendantCount(sourceIndex); - return c; - } - return 0; -} - -void KDescendantsProxyModelPrivate::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) -{ - Q_Q( KDescendantsProxyModel ); - int topRow = topLeft.row(); - int bottomRow = bottomRight.row(); - - for(int i = topRow; i <= bottomRow; ++i) - { - QModelIndex sourceTopLeft = q->sourceModel()->index(i, topLeft.column(), topLeft.parent()); - QModelIndex proxyTopLeft = q->mapFromSource(sourceTopLeft); - // TODO. If an index does not have any descendants, then we can emit in blocks of rows. - // As it is we emit once for each row. - QModelIndex sourceBottomRight = q->sourceModel()->index(i, bottomRight.column(), bottomRight.parent()); - QModelIndex proxyBottomRight = q->mapFromSource(sourceBottomRight); - emit q->dataChanged(proxyTopLeft, proxyBottomRight); - } -} - -int KDescendantsProxyModelPrivate::descendantCount(const QModelIndex &sourceIndex, int ignoreTerminals) const -{ - if (sourceIndex.column() > 0) - return 0; - - if (ObserveTerminals == ignoreTerminals) - { - if (m_terminalIndexes.contains(sourceIndex)) - { - return 0; - } - } - - Q_Q( const KDescendantsProxyModel ); - if (m_descendantsCount.contains(sourceIndex.internalId())) - { - return m_descendantsCount.value(sourceIndex.internalId()); - } - - int sourceIndexRowCount = q->sourceModel()->rowCount(sourceIndex); - if (sourceIndexRowCount == 0) - return 0; - int c = 0; - c += sourceIndexRowCount; - - int childRow = 0; - QModelIndex childIndex = q->sourceModel()->index(childRow, 0, sourceIndex); - while (childIndex.isValid()) - { - c += descendantCount(childIndex); - childRow++; - childIndex = q->sourceModel()->index(childRow, 0, sourceIndex); - } - - m_descendantsCount.insert( sourceIndex.internalId(), c ); - - return c; -} - -QModelIndex KDescendantsProxyModel::index(int r, int c, const QModelIndex& parent) const -{ - Q_D(const KDescendantsProxyModel ); - - if (!sourceModel()) - return QModelIndex(); - - - if ( (r < 0) || (c < 0) || (c >= sourceModel()->columnCount() ) ) - return QModelIndex(); - - if ( r >= d->descendantCount(parent) ) - return QModelIndex(); - - // TODO: Use is decended instead? - if (parent.isValid()) - return QModelIndex(); - - return createIndex(r, c); -} - -QModelIndex KDescendantsProxyModel::parent(const QModelIndex& proxyIndex) const -{ - Q_UNUSED(proxyIndex); - - return QModelIndex(); -} - -int KDescendantsProxyModel::columnCount(const QModelIndex &index) const -{ - Q_UNUSED( index ); - - if (!sourceModel()) - return 0; - - return sourceModel()->columnCount(); -} - -void KDescendantsProxyModel::setDisplayAncestorData( bool display ) -{ - Q_D(KDescendantsProxyModel); - d->m_displayAncestorData = display; -} - -bool KDescendantsProxyModel::displayAncestorData() const -{ - Q_D(const KDescendantsProxyModel ); - return d->m_displayAncestorData; -} - -void KDescendantsProxyModel::setAncestorSeparator( const QString &separator ) -{ - Q_D(KDescendantsProxyModel); - d->m_ancestorSeparator = separator; -} - -QString KDescendantsProxyModel::ancestorSeparator() const -{ - Q_D(const KDescendantsProxyModel ); - return d->m_ancestorSeparator; -} - -Qt::ItemFlags KDescendantsProxyModel::flags( const QModelIndex &index ) const -{ - // if index is invalid, it might be mapped to a valid source index with more flags. - // Can't allow that... - if (!index.isValid()) - return 0; - return QAbstractProxyModel::flags(index); -} - -QModelIndexList KDescendantsProxyModelPrivate::matchDescendants(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags, int until, const bool matchAll) const -{ - Q_Q(const KDescendantsProxyModel); - QModelIndexList matches; - - if (!start.isValid()) - return matches; - - const int column = start.column(); - const int firstRow = 0; - QModelIndex idx = start; - - while (idx.row() <= until) - { - Q_ASSERT(idx.isValid()); - - if (q->sourceModel()->hasChildren(idx)) - { - QModelIndex firstChild = idx.child(firstRow, column); - matches << q->match(q->mapFromSource(firstChild), role, value, hits, flags); - if (!matchAll && (matches.size() >= hits)) - { - return matches.mid(0, hits); - } - } - int row = idx.row(); - if (row == until) - { - break; - } - idx = idx.sibling(row + 1, column); - } - - return matches; -} - -QModelIndexList KDescendantsProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const -{ - Q_D(const KDescendantsProxyModel ); - - // We only really need to do all this for the AmazingCompletionRole, but there's no clean way to - // determine what that is. - - QModelIndexList sourceList; - QModelIndexList proxyList; - - QModelIndex beginIndex = start; - QModelIndex sourceStart = mapToSource(start); - QModelIndex parent = sourceModel()->parent(sourceStart); - - int parentRowCount = sourceModel()->rowCount(sourceModel()->parent(sourceStart)); - - const bool matchAll = (hits == -1); - const int firstHit = 1; - const int column = start.column(); - const int proxyRowCount = rowCount(); - - Q_ASSERT(sourceStart.column() == start.column()); - sourceList = sourceModel()->match(sourceStart, role, value, firstHit, flags); - - int lastRow; - if (sourceList.isEmpty()) - { - lastRow = parentRowCount - 1; - proxyList = d->matchDescendants(mapToSource(start), role, value, hits, flags, lastRow, matchAll); - - if (matchAll) - return proxyList; - - return proxyList.mid(0, hits); - - } else { - forever - { - QModelIndex firstIndexHit; - if (sourceList.isEmpty()) - { - lastRow = parentRowCount - 1; - } else { - firstIndexHit = sourceList.first(); - - Q_ASSERT(firstIndexHit.column() == start.column()); - - lastRow = firstIndexHit.row() - 1; - } - - proxyList << d->matchDescendants(sourceStart, role, value, hits, flags, lastRow, matchAll); - - if (sourceList.isEmpty()) - break; - - QModelIndex proxyFirst = mapFromSource(firstIndexHit); - proxyList << proxyFirst; - - if (!matchAll && ( proxyList.size() >= hits)) - { - return proxyList.mid(0, hits); - } - - if (proxyFirst.row() == proxyRowCount - 1) - break; - - sourceStart = mapToSource(index(proxyFirst.row() + 1, proxyFirst.column())); - Q_ASSERT(sourceStart.isValid()); - - sourceList = sourceModel()->match(sourceStart, role, value, firstHit, flags); - } - } - - QModelIndex nextStart = start.sibling(start.row() + parentRowCount + 1, column); - if (nextStart.isValid()) - proxyList << match(nextStart, role, value, hits, flags); - - if (matchAll) - return proxyList; - - return proxyList.mid(0, hits); -} - -Qt::DropActions KDescendantsProxyModel::supportedDropActions() const -{ - Q_ASSERT(sourceModel()); - return sourceModel()->supportedDropActions(); -} - -void KDescendantsProxyModelPrivate::sourceModelDestroyed() -{ - -} - -#include "moc_kdescendantsproxymodel_p.cpp" diff --git a/akonadi/kdescendantsproxymodel2.cpp b/akonadi/kdescendantsproxymodel2.cpp deleted file mode 100644 index 0b4d4b1c8..000000000 --- a/akonadi/kdescendantsproxymodel2.cpp +++ /dev/null @@ -1,856 +0,0 @@ -/* - Copyright (c) 2009 Stephen Kelly - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - 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 "kdescendantsproxymodel_p.h" - -#include -#include - -#include "kdebug.h" - -#define KDO(object) kDebug() << #object << object - -#include "kbihash_p.h" - -typedef KHash2Map Mapping; - -class KDescendantsProxyModelPrivate -{ - KDescendantsProxyModelPrivate(KDescendantsProxyModel * qq) - : q_ptr(qq), - m_rowCount(0), - m_ignoreNextLayoutAboutToBeChanged(false), - m_ignoreNextLayoutChanged(false), - m_relayouting(false), - m_displayAncestorData( false ), - m_ancestorSeparator( QLatin1String( " / " ) ) - { - } - - Q_DECLARE_PUBLIC(KDescendantsProxyModel) - KDescendantsProxyModel * const q_ptr; - - mutable QVector m_pendingParents; - - void scheduleProcessPendingParents() const; - void processPendingParents(); - - void synchronousMappingRefresh(); - - void updateInternalIndexes(int start, int offset); - - void resetInternalData(); - - void sourceRowsAboutToBeInserted(const QModelIndex &, int, int); - void sourceRowsInserted(const QModelIndex &, int, int); - void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int); - void sourceRowsRemoved(const QModelIndex &, int, int); - void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int); - void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); - void sourceModelAboutToBeReset(); - void sourceModelReset(); - void sourceLayoutAboutToBeChanged(); - void sourceLayoutChanged(); - void sourceDataChanged(const QModelIndex &, const QModelIndex &); - void sourceModelDestroyed(); - - Mapping m_mapping; - int m_rowCount; - QPair m_removePair; - QPair m_insertPair; - - bool m_ignoreNextLayoutAboutToBeChanged; - bool m_ignoreNextLayoutChanged; - bool m_relayouting; - - bool m_displayAncestorData; - QString m_ancestorSeparator; - - QList m_layoutChangePersistentIndexes; - QModelIndexList m_proxyIndexes; -}; - -void KDescendantsProxyModelPrivate::resetInternalData() -{ - m_rowCount = 0; - m_mapping.clear(); - m_parentMapping.clear(); - m_layoutChangePersistentIndexes.clear(); - m_proxyIndexes.clear(); -} - -void KDescendantsProxyModelPrivate::synchronousMappingRefresh() -{ - m_rowCount = 0; - m_mapping.clear(); - m_pendingParents.clear(); - - m_pendingParents.append(QModelIndex()); - - m_relayouting = true; - while (!m_pendingParents.isEmpty()) - { - processPendingParents(); - } - m_relayouting = false; -} - -void KDescendantsProxyModelPrivate::scheduleProcessPendingParents() const -{ - Q_Q(const KDescendantsProxyModel); - const_cast(this)->processPendingParents(); -} - -void KDescendantsProxyModelPrivate::processPendingParents() -{ - Q_Q(KDescendantsProxyModel); - const QVector::iterator begin = m_pendingParents.begin(); - QVector::iterator it = begin; - - // Process chunkSize elements per invokation. - static const int chunkSize = 30; - - const QVector::iterator end = - /* (m_pendingParents.size() > chunkSize) ? begin + chunkSize : */ m_pendingParents.end(); - - QVector newPendingParents; - - while (it != end && it != m_pendingParents.end()) { - const QModelIndex sourceParent = *it; - if (!sourceParent.isValid() && m_rowCount > 0) - { - // It was removed from the source model before it was inserted. - it = m_pendingParents.erase(it); - continue; - } - const int rowCount = q->sourceModel()->rowCount(sourceParent); - - Q_ASSERT(rowCount > 0); - const QPersistentModelIndex sourceIndex = q->sourceModel()->index(rowCount - 1, 0, sourceParent); - - Q_ASSERT(sourceIndex.isValid()); - - const QModelIndex proxyParent = q->mapFromSource(sourceParent); - - Q_ASSERT(sourceParent.isValid() == proxyParent.isValid()); - const int proxyEndRow = proxyParent.row() + rowCount; - const int proxyStartRow = proxyEndRow - rowCount + 1; - - if (!m_relayouting) - q->beginInsertRows(QModelIndex(), proxyStartRow, proxyEndRow); - - updateInternalIndexes(proxyStartRow, rowCount); - m_mapping.insert(sourceIndex, proxyEndRow); - it = m_pendingParents.erase(it); - m_rowCount += rowCount; - - if (!m_relayouting) - q->endInsertRows(); - - for (int sourceRow = 0; sourceRow < rowCount; ++sourceRow ) { - static const int column = 0; - const QModelIndex child = q->sourceModel()->index(sourceRow, column, sourceParent); - Q_ASSERT(child.isValid()); - - if (q->sourceModel()->hasChildren(child)) - newPendingParents.append(child); - } - } - m_pendingParents += newPendingParents; - if (!m_pendingParents.isEmpty()) - processPendingParents(); -// scheduleProcessPendingParents(); -} - -void KDescendantsProxyModelPrivate::updateInternalIndexes(int start, int offset) -{ - // TODO: Make KHash2Map support key updates and do this backwards. - QHash updates; - { - Mapping::right_const_iterator it = m_mapping.rightLowerBound(start); - const Mapping::right_const_iterator end = m_mapping.rightEnd(); - - while (it != end) - { - updates.insert(it.key() + offset, *it); - ++it; - } - } - - { - QHash::const_iterator it = updates.constBegin(); - const QHash::const_iterator end = updates.constEnd(); - - for ( ; it != end; ++it) - { - m_mapping.insert(it.value(), it.key()); - } - } - -} - -KDescendantsProxyModel::KDescendantsProxyModel(QObject *parent) - : QAbstractProxyModel(parent), d_ptr(new KDescendantsProxyModelPrivate(this)) -{ -} - -KDescendantsProxyModel::~KDescendantsProxyModel() -{ - delete d_ptr; -} - -void KDescendantsProxyModel::setRootIndex(const QModelIndex &index) -{ - Q_UNUSED(index) -} - -QModelIndexList KDescendantsProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const -{ - return QAbstractProxyModel::match(start, role, value, hits, flags); -} - -void KDescendantsProxyModel::setDisplayAncestorData( bool display ) -{ - Q_D(KDescendantsProxyModel); - d->m_displayAncestorData = display; -} - -bool KDescendantsProxyModel::displayAncestorData() const -{ - Q_D(const KDescendantsProxyModel ); - return d->m_displayAncestorData; -} - -void KDescendantsProxyModel::setAncestorSeparator( const QString &separator ) -{ - Q_D(KDescendantsProxyModel); - d->m_ancestorSeparator = separator; -} - -QString KDescendantsProxyModel::ancestorSeparator() const -{ - Q_D(const KDescendantsProxyModel ); - return d->m_ancestorSeparator; -} - - -void KDescendantsProxyModel::setSourceModel(QAbstractItemModel *_sourceModel) -{ - beginResetModel(); - - if (_sourceModel) { - disconnect(_sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); - disconnect(_sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); - disconnect(_sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); - disconnect(_sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); -// disconnect(_sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), -// this, SLOT(sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); -// disconnect(_sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), -// this, SLOT(sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - disconnect(_sourceModel, SIGNAL(modelAboutToBeReset()), - this, SLOT(sourceModelAboutToBeReset())); - disconnect(_sourceModel, SIGNAL(modelReset()), - this, SLOT(sourceModelReset())); - disconnect(_sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); - disconnect(_sourceModel, SIGNAL(layoutAboutToBeChanged()), - this, SLOT(sourceLayoutAboutToBeChanged())); - disconnect(_sourceModel, SIGNAL(layoutChanged()), - this, SLOT(sourceLayoutChanged())); - disconnect(_sourceModel, SIGNAL(destroyed()), - this, SLOT(sourceModelDestroyed())); - } - - QAbstractProxyModel::setSourceModel(_sourceModel); - - if (_sourceModel) { - connect(_sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), - SLOT(sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); - connect(_sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), - SLOT(sourceRowsInserted(const QModelIndex &, int, int))); - connect(_sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - SLOT(sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(_sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); -// connect(_sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), -// SLOT(sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); -// connect(_sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), -// SLOT(sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - connect(_sourceModel, SIGNAL(modelAboutToBeReset()), - SLOT(sourceModelAboutToBeReset())); - connect(_sourceModel, SIGNAL(modelReset()), - SLOT(sourceModelReset())); - connect(_sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); - connect(_sourceModel, SIGNAL(layoutAboutToBeChanged()), - SLOT(sourceLayoutAboutToBeChanged())); - connect(_sourceModel, SIGNAL(layoutChanged()), - SLOT(sourceLayoutChanged())); - connect(_sourceModel, SIGNAL(destroyed()), - SLOT(sourceModelDestroyed())); - } - - endResetModel(); -} - -QModelIndex KDescendantsProxyModel::parent(const QModelIndex &index) const -{ - Q_UNUSED(index) - return QModelIndex(); -} - -bool KDescendantsProxyModel::hasChildren(const QModelIndex &parent) const -{ - Q_D(const KDescendantsProxyModel); - return !(d->m_mapping.isEmpty() || parent.isValid()); -} - -int KDescendantsProxyModel::rowCount(const QModelIndex &parent) const -{ - Q_D(const KDescendantsProxyModel); - if (d->m_pendingParents.contains(parent) || parent.isValid() || !sourceModel()) - return 0; - - if (d->m_mapping.isEmpty() && sourceModel()->hasChildren()) - { - const_cast(d)->synchronousMappingRefresh(); - } - return d->m_rowCount; -} - -QModelIndex KDescendantsProxyModel::index(int row, int column, const QModelIndex &parent) const -{ - if (parent.isValid()) - return QModelIndex(); - - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - return createIndex(row, column); -} - -QModelIndex KDescendantsProxyModel::mapToSource(const QModelIndex &proxyIndex) const -{ - Q_D(const KDescendantsProxyModel); - if (d->m_mapping.isEmpty() || !proxyIndex.isValid() || !sourceModel()) - return QModelIndex(); - - const Mapping::right_const_iterator result = d->m_mapping.rightLowerBound(proxyIndex.row()); - Q_ASSERT(result != d->m_mapping.rightEnd()); - - const int proxyLastRow = result.key(); - const QModelIndex sourceLastChild = result.value(); - Q_ASSERT(sourceLastChild.isValid()); - - // proxyLastRow is greater than proxyIndex.row(). - // sourceLastChild is vertically below the result we're looking for - // and not necessarily in the correct parent. - // We travel up through its parent hierarchy until we are in the - // right parent, then return the correct sibling. - - // Source: Proxy: Row - // - A - A - 0 - // - B - B - 1 - // - C - C - 2 - // - D - D - 3 - // - - E - E - 4 - // - - F - F - 5 - // - - G - G - 6 - // - - H - H - 7 - // - - I - I - 8 - // - - - J - J - 9 - // - - - K - K - 10 - // - - - L - L - 11 - // - - M - M - 12 - // - - N - N - 13 - // - O - O - 14 - - // Note that L, N and O are lastChildIndexes, and therefore have a mapping. If we - // are trying to map G from the proxy to the source, We at this point have an iterator - // pointing to (L -> 11). The proxy row of G is 6. (proxyIndex.row() == 6). We seek the - // sourceIndex which is vertically above L by the distance proxyLastRow - proxyIndex.row(). - // In this case the verticalDistance is 5. - - int verticalDistance = proxyLastRow - proxyIndex.row(); - - // We traverse the ancestors of L, until we can index the desired row in the source. - - QModelIndex ancestor = sourceLastChild; - while (ancestor.isValid()) - { - const int ancestorRow = ancestor.row(); - if (verticalDistance <= ancestorRow) - { - return ancestor.sibling(ancestorRow - verticalDistance, proxyIndex.column()); - } - verticalDistance -= (ancestorRow + 1); - ancestor = ancestor.parent(); - } - Q_ASSERT(!"Didn't find target row."); - return QModelIndex(); -} - -QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex &sourceIndex) const -{ - Q_D(const KDescendantsProxyModel); - - if (!sourceModel()) - return QModelIndex(); - - if (d->m_mapping.isEmpty()) - return QModelIndex(); - - - { - // TODO: Consider a parent Mapping to speed this up. - - Mapping::right_const_iterator it = d->m_mapping.rightConstBegin(); - const Mapping::right_const_iterator end = d->m_mapping.rightConstEnd(); - const QModelIndex sourceParent = sourceIndex.parent(); - Mapping::right_const_iterator result = end; - - for ( ; it != end; ++it ) - { - QModelIndex index = it.value(); - bool found_block = false; - while (index.isValid()) - { - const QModelIndex ancestor = index.parent(); - if (ancestor == sourceParent && index.row() >= sourceIndex.row()) - { - found_block = true; - if (result == end || it.key() < result.key()) - { - result = it; - break; // Leave the while loop. index is still valid. - } - } - index = ancestor; - } - if (found_block && !index.isValid()) - // Looked through the ascendants of it.key() without finding sourceParent. - // That means we've already got the result we need. - break; - } - Q_ASSERT(result != end); - const QModelIndex sourceLastChild = result.value(); - int proxyRow = result.key(); - QModelIndex index = sourceLastChild; - while (index.isValid()) - { - const QModelIndex ancestor = index.parent(); - if (ancestor == sourceParent) - { - return createIndex(proxyRow - (index.row() - sourceIndex.row()), sourceIndex.column()); - } - proxyRow -= (index.row() + 1); - index = ancestor; - } - Q_ASSERT(!"Didn't find valid proxy mapping."); - return QModelIndex(); - } - -} - -int KDescendantsProxyModel::columnCount(const QModelIndex &parent) const -{ - if (parent.isValid() /* || rowCount(parent) == 0 */ || !sourceModel()) - return 0; - - return sourceModel()->columnCount(); -} - -QVariant KDescendantsProxyModel::data(const QModelIndex &index, int role) const -{ - Q_D(const KDescendantsProxyModel ); - - if (!sourceModel()) - return QVariant(); - - if (!index.isValid()) - return sourceModel()->data(index, role); - - QModelIndex sourceIndex = mapToSource( index ); - - if ((d->m_displayAncestorData) && ( role == Qt::DisplayRole ) ) - { - if (!sourceIndex.isValid()) - { - return QVariant(); - } - QString displayData = sourceIndex.data().toString(); - sourceIndex = sourceIndex.parent(); - while (sourceIndex.isValid()) - { - displayData.prepend(d->m_ancestorSeparator); - displayData.prepend(sourceIndex.data().toString()); - sourceIndex = sourceIndex.parent(); - } - return displayData; - } else { - return sourceIndex.data(role); - } -} - -QVariant KDescendantsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (!sourceModel() || columnCount() <= section) - return QVariant(); - - return QAbstractProxyModel::headerData(section, orientation, role); -} - -Qt::ItemFlags KDescendantsProxyModel::flags(const QModelIndex &index) const -{ - if (!index.isValid() || !sourceModel()) - return QAbstractProxyModel::flags(index); - - const QModelIndex srcIndex = mapToSource(index); - Q_ASSERT(srcIndex.isValid()); - return sourceModel()->flags(srcIndex); -} - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - - if (!q->sourceModel()->hasChildren(parent)) - { - // parent was not a parent before. - return; - } - - int proxyStart = -1; - - const int rowCount = q->sourceModel()->rowCount(parent); - - if (rowCount > start) - { - const QModelIndex belowStart = q->sourceModel()->index(start, 0, parent); - proxyStart = q->mapFromSource(belowStart).row(); - } else if (rowCount == 0) - { - proxyStart = q->mapFromSource(parent).row() + 1; - } else { - Q_ASSERT(rowCount == start); - static const int column = 0; - QModelIndex idx = q->sourceModel()->index(rowCount - 1, column, parent); - while (q->sourceModel()->hasChildren(idx)) - { - idx = q->sourceModel()->index(q->sourceModel()->rowCount(idx) - 1, column, idx); - } - // The last item in the list is getting a sibling below it. - proxyStart = q->mapFromSource(idx).row() + 1; - } - const int proxyEnd = proxyStart + (end - start); - - m_insertPair = qMakePair(proxyStart, proxyEnd); - q->beginInsertRows(QModelIndex(), proxyStart, proxyEnd); -} - -void KDescendantsProxyModelPrivate::sourceRowsInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - - const QModelIndex sourceStart = q->sourceModel()->index(start, 0, parent); - Q_ASSERT(sourceStart.isValid()); - - const int rowCount = q->sourceModel()->rowCount(parent); - Q_ASSERT(rowCount > 0); - - const int difference = end - start + 1; - - if (rowCount == difference) - { - // @p parent was not a parent before. - m_pendingParents.append(parent); - scheduleProcessPendingParents(); - return; - } - - const int proxyStart = m_insertPair.first; - - Q_ASSERT(proxyStart >= 0); - - updateInternalIndexes(proxyStart, difference); - - if (rowCount - 1 == end) - { - // The previously last row (the mapped one) is no longer the last. - // For example, - - // - A - A 0 - // - - B - B 1 - // - - C - C 2 - // - - - D - D 3 - // - - - E -> - E 4 - // - - F - F 5 - // - - G -> - G 6 - // - H - H 7 - // - I -> - I 8 - - // As last children, E, F and G have mappings. - // Consider that 'J' is appended to the children of 'C', below 'E'. - - // - A - A 0 - // - - B - B 1 - // - - C - C 2 - // - - - D - D 3 - // - - - E -> - E 4 - // - - - J - ??? 5 - // - - F - F 6 - // - - G -> - G 7 - // - H - H 8 - // - I -> - I 9 - - // The updateInternalIndexes call above will have updated the F and G mappings correctly because proxyStart is 5. - // That means that E -> 4 was not affected by the updateInternalIndexes call. - // Now the mapping for E -> 4 needs to be updated so that it's a mapping for J -> 5. - - Q_ASSERT(!m_mapping.isEmpty()); - static const int column = 0; - const QModelIndex oldIndex = q->sourceModel()->index(rowCount - 1 - difference, column, parent); - Q_ASSERT(m_mapping.leftContains(oldIndex)); - - // oldIndex is E in the source. proxyRow is 4. - const int proxyRow = m_mapping.takeLeft(oldIndex); - const QModelIndex newIndex = q->sourceModel()->index(rowCount - 1, column, parent); - - // newIndex is J. (proxyRow + difference) is 5. - m_mapping.insert(newIndex, proxyRow + difference); - } - - for (int row = start; row <= end; ++row) - { - static const int column = 0; - const QModelIndex idx = q->sourceModel()->index(row, column, parent); - Q_ASSERT(idx.isValid()); - if (q->sourceModel()->hasChildren(idx)) - m_pendingParents.append(idx); - } - - m_rowCount += difference; - - scheduleProcessPendingParents(); - q->endInsertRows(); -} - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - - const int proxyStart = q->mapFromSource(q->sourceModel()->index(start, 0, parent)).row(); - const int proxyEnd = q->mapFromSource(q->sourceModel()->index(end, 0, parent)).row(); - - m_removePair = qMakePair(proxyStart, proxyEnd); - - q->beginRemoveRows(QModelIndex(), proxyStart, proxyEnd); -} - -void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KDescendantsProxyModel); - Q_UNUSED(end) - - const int rowCount = q->sourceModel()->rowCount(parent); - - - const int proxyStart = m_removePair.first; - const int proxyEnd = m_removePair.second; - - const int difference = proxyEnd - proxyStart + 1; - { - Mapping::right_iterator it = m_mapping.rightLowerBound(proxyStart); - const Mapping::right_iterator endIt = m_mapping.rightUpperBound(proxyEnd); - - if (endIt != m_mapping.rightEnd()) - while (it != endIt) - it = m_mapping.eraseRight(it); - else - while (it != m_mapping.rightUpperBound(proxyEnd)) - it = m_mapping.eraseRight(it); - } - - m_removePair = qMakePair(-1, -1); - m_rowCount -= difference; - Q_ASSERT(m_rowCount >= 0); - - updateInternalIndexes(proxyStart, -1 * difference); - - if (rowCount == start && rowCount != 0) - { - static const int column = 0; - const QModelIndex newIndex = q->sourceModel()->index(rowCount - 1, column, parent); - m_mapping.insert(newIndex, proxyStart - 1); - } - - q->endRemoveRows(); -} - -void KDescendantsProxyModelPrivate::sourceRowsAboutToBeMoved(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destStart) -{ - Q_UNUSED(srcParent) - Q_UNUSED(srcStart) - Q_UNUSED(srcEnd) - Q_UNUSED(destParent) - Q_UNUSED(destStart) - Q_Q(KDescendantsProxyModel); - q->beginResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceRowsMoved(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destStart) -{ - Q_UNUSED(srcParent) - Q_UNUSED(srcStart) - Q_UNUSED(srcEnd) - Q_UNUSED(destParent) - Q_UNUSED(destStart) - Q_Q(KDescendantsProxyModel); - resetInternalData(); - q->endResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceModelAboutToBeReset() -{ - Q_Q(KDescendantsProxyModel); - q->beginResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceModelReset() -{ - Q_Q(KDescendantsProxyModel); - resetInternalData(); - if (q->sourceModel()->hasChildren()) - { - m_pendingParents.append(QModelIndex()); - scheduleProcessPendingParents(); - } - q->endResetModel(); -} - -void KDescendantsProxyModelPrivate::sourceLayoutAboutToBeChanged() -{ - Q_Q(KDescendantsProxyModel); - - if (m_ignoreNextLayoutChanged) { - m_ignoreNextLayoutChanged = false; - return; - } - - if (m_mapping.isEmpty()) - return; - - QPersistentModelIndex srcPersistentIndex; - foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { - m_proxyIndexes << proxyPersistentIndex; - Q_ASSERT(proxyPersistentIndex.isValid()); - srcPersistentIndex = q->mapToSource(proxyPersistentIndex); - Q_ASSERT(srcPersistentIndex.isValid()); - m_layoutChangePersistentIndexes << srcPersistentIndex; - } - - q->layoutAboutToBeChanged(); -} - -void KDescendantsProxyModelPrivate::sourceLayoutChanged() -{ - Q_Q(KDescendantsProxyModel); - - if (m_ignoreNextLayoutAboutToBeChanged) { - m_ignoreNextLayoutAboutToBeChanged = false; - return; - } - - if (m_mapping.isEmpty()) - return; - - m_rowCount = 0; - - synchronousMappingRefresh(); - - for (int i = 0; i < m_proxyIndexes.size(); ++i) { - q->changePersistentIndex(m_proxyIndexes.at(i), q->mapFromSource(m_layoutChangePersistentIndexes.at(i))); - } - - m_layoutChangePersistentIndexes.clear(); - m_proxyIndexes.clear(); - - q->layoutChanged(); -} - -void KDescendantsProxyModelPrivate::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) -{ - Q_Q(KDescendantsProxyModel); - - const int topRow = topLeft.row(); - const int bottomRow = bottomRight.row(); - - for(int i = topRow; i <= bottomRow; ++i) - { - const QModelIndex sourceTopLeft = q->sourceModel()->index(i, topLeft.column(), topLeft.parent()); - const QModelIndex proxyTopLeft = q->mapFromSource(sourceTopLeft); - // TODO. If an index does not have any descendants, then we can emit in blocks of rows. - // As it is we emit once for each row. - const QModelIndex sourceBottomRight = q->sourceModel()->index(i, bottomRight.column(), bottomRight.parent()); - const QModelIndex proxyBottomRight = q->mapFromSource(sourceBottomRight); - emit q->dataChanged(proxyTopLeft, proxyBottomRight); - } -} - -void KDescendantsProxyModelPrivate::sourceModelDestroyed() -{ - Q_Q(KDescendantsProxyModel); - resetInternalData(); - q->endResetModel(); -} - -QMimeData* KDescendantsProxyModel::mimeData( const QModelIndexList & indexes ) const -{ - if (!sourceModel()) - return QAbstractProxyModel::mimeData(indexes); - Q_ASSERT(sourceModel()); - QModelIndexList sourceIndexes; - foreach(const QModelIndex& index, indexes) - sourceIndexes << mapToSource(index); - return sourceModel()->mimeData(sourceIndexes); -} - -QStringList KDescendantsProxyModel::mimeTypes() const -{ - if (!sourceModel()) - return QAbstractProxyModel::mimeTypes(); - Q_ASSERT(sourceModel()); - return sourceModel()->mimeTypes(); -} - -Qt::DropActions KDescendantsProxyModel::supportedDropActions() const -{ - if (!sourceModel()) - return QAbstractProxyModel::supportedDropActions(); - return sourceModel()->supportedDropActions(); -} - -#include "moc_kdescendantsproxymodel_p.cpp" diff --git a/akonadi/kdescendantsproxymodel_p.h b/akonadi/kdescendantsproxymodel_p.h deleted file mode 100644 index a6b9c994d..000000000 --- a/akonadi/kdescendantsproxymodel_p.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - Copyright (c) 2009 Stephen Kelly - - 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 KDESCENDANTSPROXYMODEL_P_H -#define KDESCENDANTSPROXYMODEL_P_H - -#include - -class KDescendantsProxyModelPrivate; - -/** -@brief Proxy Model for restructuring a Tree into a list. - -A KDescendantsProxyModel may be used to alter how the items in the tree are presented. - -Given a model which is represented as a tree: - -\image html entitytreemodel.png "A plain EntityTreeModel in a view" - -The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list. - -@code -// ... Create an entityTreeModel -KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this); -descProxy->setSourceModel(entityTree); -view->setModel(descProxy); -@endcode - -\image html descendantentitiesproxymodel.png "A KDescendantsProxyModel." - -KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display. - -@code -// ... Create an entityTreeModel -KDescendantsProxyModel *descProxy = new KDescendantesProxyModel(this); -descProxy->setSourceModel(entityTree); - -// #### This is new -descProxy->setDisplayAncestorData(true, QString( " / " )); - -view->setModel(descProxy); - -@endcode - -\image html descendantentitiesproxymodel-withansecnames.png "A KDescendantsProxyModel with ancestor names." - -@since 4.4 -@author Stephen Kelly -*/ -class KDescendantsProxyModel : public QAbstractProxyModel -{ - Q_OBJECT - - public: - - /** - * Creates a new descendant entities proxy model. - * - * @param parent The parent object. - */ - explicit KDescendantsProxyModel( QObject *parent = 0 ); - - /** - * Destroys the descendant entities proxy model. - */ - virtual ~KDescendantsProxyModel(); - - /** - * Sets the source @p model of the proxy. - */ - virtual void setSourceModel( QAbstractItemModel *model ); - - /** - * Sets the root index to @p index. This is the root of the proxy model. - * - * @param index The root index in the *source* model which will be shown in this model. - * If the index is invalid, the model is empty. - * - * \note You must set the model before setting the root index. - */ - void setRootIndex( const QModelIndex &index); - - /** - * Set whether to show ancestor data in the model. If @p display is true, then - * a source model which is displayed as - * - * @code - * -> "Item 0-0" (this is row-depth) - * -> -> "Item 0-1" - * -> -> "Item 1-1" - * -> -> -> "Item 0-2" - * -> -> -> "Item 1-2" - * -> "Item 1-0" - * @endcode - * - * will be displayed as - * - * @code - * -> *Item 0-0" - * -> "Item 0-0 / Item 0-1" - * -> "Item 0-0 / Item 1-1" - * -> "Item 0-0 / Item 1-1 / Item 0-2" - * -> "Item 0-0 / Item 1-1 / Item 1-2" - * -> "Item 1-0" - * @endcode - * - * If @p display is false, the proxy will show - * - * @code - * -> *Item 0-0" - * -> "Item 0-1" - * -> "Item 1-1" - * -> "Item 0-2" - * -> "Item 1-2" - * -> "Item 1-0" - * @endcode - * - * Default is false. - */ - void setDisplayAncestorData( bool display ); - - /** - * Whether ancestor data will be displayed. - */ - bool displayAncestorData() const; - - /** - * Sets the ancestor @p separator used between data of ancestors. - */ - void setAncestorSeparator( const QString &separator ); - - /** - * Separator used between data of ancestors. - */ - QString ancestorSeparator() const; - - /** - * Returns the number of descendant entries for the given model @p index. - */ - int descendantCount( const QModelIndex &index ) const; - - QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const; - QModelIndex mapToSource ( const QModelIndex & proxyIndex ) const; - - virtual Qt::ItemFlags flags( const QModelIndex &index ) const; - QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; - - virtual QMimeData* mimeData( const QModelIndexList & indexes ) const; - virtual QStringList mimeTypes() const; - - virtual bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const; - virtual QModelIndex index(int, int, const QModelIndex &parent = QModelIndex() ) const; - virtual QModelIndex parent(const QModelIndex&) const; - virtual int columnCount(const QModelIndex& index = QModelIndex()) const; - - virtual Qt::DropActions supportedDropActions() const; - - /** - Reimplemented to match all descendants. - */ - virtual QModelIndexList match(const QModelIndex& start, int role, const QVariant& value, - int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const; - - -private: - Q_DECLARE_PRIVATE( KDescendantsProxyModel ) - //@cond PRIVATE - KDescendantsProxyModelPrivate *d_ptr; - - Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int)) - Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int)) - Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)) - Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int)) - Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)) - Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)) - Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset()) - Q_PRIVATE_SLOT(d_func(), void sourceModelReset()) - Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged()) - Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged()) - Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed()) - - Q_PRIVATE_SLOT(d_func(), void processPendingParents()) - - - // Make these private, they shouldn't be called by applications -// virtual bool insertRows(int , int, const QModelIndex & = QModelIndex()); -// virtual bool insertColumns(int, int, const QModelIndex & = QModelIndex()); -// virtual bool removeRows(int, int, const QModelIndex & = QModelIndex()); -// virtual bool removeColumns(int, int, const QModelIndex & = QModelIndex()); - - - //@endcond -}; - -#endif