1
/* This file is part of Zanshin Todo.
3
Copyright 2009 Kevin Ottens <ervin@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License or (at your option) version 3 or any later version
9
accepted by the membership of KDE e.V. (or its successor approved
10
by the membership of KDE e.V.), which shall act as a proxy
11
defined in Section 14 of version 3 of the license.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
#include "quickselectdialog.h"
27
#include <KDE/KLocale>
29
#include <QtGui/QLayout>
30
#include <QtGui/QTreeView>
32
#include "globalmodel.h"
33
#include "projectsmodel.h"
34
#include "contextsmodel.h"
35
#include "todocategoriesmodel.h"
36
#include "todoflatmodel.h"
37
#include "todotreemodel.h"
39
QuickSelectDialog::QuickSelectDialog(QWidget *parent, Mode mode, ActionType action)
40
: KDialog(parent), m_tree(0), m_mode(mode)
44
if (mode==ContextMode) {
47
caption = i18n("Move Actions to Context");
50
caption = i18n("Copy Actions to Context");
53
caption = i18n("Jump to Context");
56
} else if (mode==ProjectMode) {
59
caption = i18n("Move Actions to Project or Folder");
62
caption = i18n("Copy Actions to Project or Folder");
65
caption = i18n("Jump to Project or Folder");
69
kError() << "Shouldn't happen";
73
setButtons(Ok|Cancel);
75
QWidget *page = mainWidget();
76
page->setLayout(new QVBoxLayout(page));
78
m_tree = new QTreeView(page);
79
m_tree->setSortingEnabled(true);
80
m_tree->sortByColumn(0, Qt::AscendingOrder);
81
page->layout()->addWidget(m_tree);
85
m_tree->setModel(GlobalModel::projects());
88
m_tree->setModel(GlobalModel::contexts());
92
m_tree->setSelectionMode(QAbstractItemView::SingleSelection);
93
m_tree->setCurrentIndex(m_tree->model()->index(0, 0));
95
m_tree->setFocus(Qt::OtherFocusReason);
98
QString QuickSelectDialog::selectedId() const
100
if (m_mode==ProjectMode) {
101
return projectSelectedId();
103
return contextSelectedId();
107
QString QuickSelectDialog::contextSelectedId() const
109
QModelIndex index = m_tree->selectionModel()->currentIndex();
110
QModelIndex sourceIndex = GlobalModel::contexts()->mapToSource(index);
112
return GlobalModel::todoCategories()->data(sourceIndex.sibling(sourceIndex.row(), 0)).toString();
115
QString QuickSelectDialog::projectSelectedId() const
117
QModelIndex index = m_tree->selectionModel()->currentIndex();
118
QModelIndex sourceIndex = GlobalModel::projects()->mapToSource(index);
120
return GlobalModel::todoTree()->data(sourceIndex.sibling(sourceIndex.row(), TodoFlatModel::RemoteId)).toString();