~ubuntu-branches/ubuntu/wily/zanshin/wily-proposed

« back to all changes in this revision

Viewing changes to src/quickselectdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-08-13 23:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20090813231932-lewqphiry1qs7w80
Tags: upstream-0.1+svn1006410
ImportĀ upstreamĀ versionĀ 0.1+svn1006410

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Zanshin Todo.
 
2
 
 
3
   Copyright 2009 Kevin Ottens <ervin@kde.org>
 
4
 
 
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.
 
12
 
 
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.
 
17
 
 
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,
 
21
   USA.
 
22
*/
 
23
 
 
24
#include "quickselectdialog.h"
 
25
 
 
26
#include <KDE/KDebug>
 
27
#include <KDE/KLocale>
 
28
 
 
29
#include <QtGui/QLayout>
 
30
#include <QtGui/QTreeView>
 
31
 
 
32
#include "globalmodel.h"
 
33
#include "projectsmodel.h"
 
34
#include "contextsmodel.h"
 
35
#include "todocategoriesmodel.h"
 
36
#include "todoflatmodel.h"
 
37
#include "todotreemodel.h"
 
38
 
 
39
QuickSelectDialog::QuickSelectDialog(QWidget *parent, Mode mode, ActionType action)
 
40
    : KDialog(parent), m_tree(0), m_mode(mode)
 
41
{
 
42
    QString caption;
 
43
 
 
44
    if (mode==ContextMode) {
 
45
        switch (action) {
 
46
        case MoveAction:
 
47
            caption = i18n("Move Actions to Context");
 
48
            break;
 
49
        case CopyAction:
 
50
            caption = i18n("Copy Actions to Context");
 
51
            break;
 
52
        case JumpAction:
 
53
            caption = i18n("Jump to Context");
 
54
            break;
 
55
        }
 
56
    } else if (mode==ProjectMode) {
 
57
        switch (action) {
 
58
        case MoveAction:
 
59
            caption = i18n("Move Actions to Project or Folder");
 
60
            break;
 
61
        case CopyAction:
 
62
            caption = i18n("Copy Actions to Project or Folder");
 
63
            break;
 
64
        case JumpAction:
 
65
            caption = i18n("Jump to Project or Folder");
 
66
            break;
 
67
        }
 
68
    } else {
 
69
        kError() << "Shouldn't happen";
 
70
    }
 
71
 
 
72
    setCaption(caption);
 
73
    setButtons(Ok|Cancel);
 
74
 
 
75
    QWidget *page = mainWidget();
 
76
    page->setLayout(new QVBoxLayout(page));
 
77
 
 
78
    m_tree = new QTreeView(page);
 
79
    m_tree->setSortingEnabled(true);
 
80
    m_tree->sortByColumn(0, Qt::AscendingOrder);
 
81
    page->layout()->addWidget(m_tree);
 
82
 
 
83
    switch (mode) {
 
84
    case ProjectMode:
 
85
        m_tree->setModel(GlobalModel::projects());
 
86
        break;
 
87
    case ContextMode:
 
88
        m_tree->setModel(GlobalModel::contexts());
 
89
        break;
 
90
    }
 
91
 
 
92
    m_tree->setSelectionMode(QAbstractItemView::SingleSelection);
 
93
    m_tree->setCurrentIndex(m_tree->model()->index(0, 0));
 
94
    m_tree->expandAll();
 
95
    m_tree->setFocus(Qt::OtherFocusReason);
 
96
}
 
97
 
 
98
QString QuickSelectDialog::selectedId() const
 
99
{
 
100
    if (m_mode==ProjectMode) {
 
101
        return projectSelectedId();
 
102
    } else {
 
103
        return contextSelectedId();
 
104
    }
 
105
}
 
106
 
 
107
QString QuickSelectDialog::contextSelectedId() const
 
108
{
 
109
    QModelIndex index = m_tree->selectionModel()->currentIndex();
 
110
    QModelIndex sourceIndex = GlobalModel::contexts()->mapToSource(index);
 
111
 
 
112
    return GlobalModel::todoCategories()->data(sourceIndex.sibling(sourceIndex.row(), 0)).toString();
 
113
}
 
114
 
 
115
QString QuickSelectDialog::projectSelectedId() const
 
116
{
 
117
    QModelIndex index = m_tree->selectionModel()->currentIndex();
 
118
    QModelIndex sourceIndex = GlobalModel::projects()->mapToSource(index);
 
119
 
 
120
    return GlobalModel::todoTree()->data(sourceIndex.sibling(sourceIndex.row(), TodoFlatModel::RemoteId)).toString();
 
121
}