Move code to get selected itmes in treeview class

Allow to save/restore dialog box size
Start to implement "add folder" as in old kmail (not implemented yet)

svn path=/branches/work/akonadi-ports/kdepim/; revision=1033078
wilder-work
Laurent Montel 17 years ago
parent ea8594d0f7
commit af9b726f5a
  1. 31
      folderselectiontreeview.cpp
  2. 6
      folderselectiontreeview.h
  3. 67
      folderselectiontreeviewdialog.cpp
  4. 5
      folderselectiontreeviewdialog.h

@ -28,6 +28,8 @@
#include <akonadi/favoritecollectionsmodel.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/entityfilterproxymodel.h>
#include <akonadi/collection.h>
class FolderSelectionTreeView::FolderSelectionTreeViewPrivate
{
@ -113,4 +115,33 @@ QModelIndex FolderSelectionTreeView::currentIndex() const
return d->collectionFolderView->currentIndex();
}
Akonadi::Collection FolderSelectionTreeView::selectedCollection() const
{
if ( d->collectionFolderView->selectionMode() == QAbstractItemView::SingleSelection ) {
const QModelIndex index = d->collectionFolderView->currentIndex();
if ( index.isValid() )
return index.model()->data( index, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
}
return Akonadi::Collection();
}
Akonadi::Collection::List FolderSelectionTreeView::selectedCollections() const
{
Akonadi::Collection::List collections;
const QItemSelectionModel *selectionModel = d->collectionFolderView->selectionModel();
const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
foreach ( const QModelIndex &index, selectedIndexes ) {
if ( index.isValid() ) {
const Akonadi::Collection collection = index.model()->data( index, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
if ( collection.isValid() )
collections.append( collection );
}
}
return collections;
}
#include "folderselectiontreeview.moc"

@ -21,9 +21,8 @@
#include <QWidget>
#include <QAbstractItemView>
#include <akonadi/collection.h>
class QItemSelectionModel;
class FolderSelectionTreeView : public QWidget
{
Q_OBJECT
@ -39,6 +38,9 @@ public:
QModelIndex currentIndex() const;
Akonadi::Collection selectedCollection() const;
Akonadi::Collection::List selectedCollections() const;
private:
class FolderSelectionTreeViewPrivate;

@ -17,29 +17,52 @@
*/
#include "folderselectiontreeviewdialog.h"
#include <QVBoxLayout>
#include "folderselectiontreeview.h"
#include <akonadi/collection.h>
#include <akonadi/entitytreemodel.h>
#include <KLocale>
FolderSelectionTreeViewDialog::FolderSelectionTreeViewDialog( QWidget *parent )
:KDialog( parent )
{
setButtons( Ok | Cancel | User1 );
setObjectName( "folder dialog" );
setButtonGuiItem( User1, KGuiItem( i18n("&New Subfolder..."), "folder-new",
i18n("Create a new subfolder under the currently selected folder") ) );
QWidget *widget = mainWidget();
QVBoxLayout *layout = new QVBoxLayout( widget );
treeview = new FolderSelectionTreeView( this );
layout->addWidget( treeview );
enableButton( KDialog::Ok, false );
enableButton( KDialog::User1, false );
connect(treeview->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged()));
connect(this, SIGNAL( user1Clicked() ), this, SLOT( slotAddChildFolder() ) );
readConfig();
}
FolderSelectionTreeViewDialog::~FolderSelectionTreeViewDialog()
{
writeConfig();
}
void FolderSelectionTreeViewDialog::slotAddChildFolder()
{
//TODO implement it.
}
void FolderSelectionTreeViewDialog::slotSelectionChanged()
{
enableButton(KDialog::Ok, treeview->selectionModel()->selectedIndexes().count() > 0);
const bool enablebuttons = ( treeview->selectionModel()->selectedIndexes().count() > 0 );
enableButton(KDialog::Ok, enablebuttons);
enableButton(KDialog::User1, enablebuttons );
}
void FolderSelectionTreeViewDialog::setSelectionMode( QAbstractItemView::SelectionMode mode )
@ -55,29 +78,33 @@ QAbstractItemView::SelectionMode FolderSelectionTreeViewDialog::selectionMode()
Akonadi::Collection FolderSelectionTreeViewDialog::selectedCollection() const
{
if ( treeview->selectionMode() == QAbstractItemView::SingleSelection ) {
const QModelIndex index = treeview->currentIndex();
if ( index.isValid() )
return index.model()->data( index, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
}
return Akonadi::Collection();
return treeview->selectedCollection();
}
Akonadi::Collection::List FolderSelectionTreeViewDialog::selectedCollections() const
{
Akonadi::Collection::List collections;
const QItemSelectionModel *selectionModel = treeview->selectionModel();
const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
foreach ( const QModelIndex &index, selectedIndexes ) {
if ( index.isValid() ) {
const Akonadi::Collection collection = index.model()->data( index, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
if ( collection.isValid() )
collections.append( collection );
}
}
return collections;
return treeview->selectedCollections();
}
static const char * myConfigGroupName = "FolderSelectionDialog";
void FolderSelectionTreeViewDialog::readConfig()
{
KSharedConfigPtr config = KGlobal::config();
KConfigGroup group( config, myConfigGroupName );
QSize size = group.readEntry( "Size", QSize() );
if ( !size.isEmpty() )
resize( size );
else
resize( 500, 300 );
}
void FolderSelectionTreeViewDialog::writeConfig()
{
KSharedConfig::Ptr config = KGlobal::config();
KConfigGroup group( config, myConfigGroupName );
group.writeEntry( "Size", size() );
}
#include "folderselectiontreeviewdialog.moc"

@ -42,6 +42,11 @@ public:
private slots:
void slotSelectionChanged();
void slotAddChildFolder();
protected:
void readConfig();
void writeConfig();
private:
FolderSelectionTreeView *treeview;

Loading…
Cancel
Save