1 | /* This file is part of the KDE project |
2 | * Copyright (C) 2009, 2012 Dag Andersen <danders@get2net.dk> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "kptschedulesdocker.h" |
21 | |
22 | #include "kptschedule.h" |
23 | #include <kptdebug.h> |
24 | |
25 | #include <KoToolManager.h> |
26 | #include <KoShapeManager.h> |
27 | |
28 | #include <klocale.h> |
29 | |
30 | #include <QAbstractItemView> |
31 | #include <QModelIndex> |
32 | #include <QModelIndexList> |
33 | #include <QTreeView> |
34 | #include <QVBoxLayout> |
35 | #include <QTimer> |
36 | |
37 | |
38 | namespace KPlato |
39 | { |
40 | |
41 | SchedulesDocker::SchedulesDocker() |
42 | { |
43 | setWindowTitle(i18n("Schedule Selector" )); |
44 | m_view = new QTreeView( this ); |
45 | m_sfModel.setSourceModel( &m_model ); |
46 | m_view->setModel( &m_sfModel ); |
47 | m_sfModel.setFilterKeyColumn ( ScheduleModel::ScheduleScheduled ); |
48 | m_sfModel.setFilterRole( Qt::EditRole ); |
49 | m_sfModel.setFilterFixedString( "true" ); |
50 | m_sfModel.setDynamicSortFilter ( true ); |
51 | |
52 | for( int c = 1; c < m_model.columnCount(); ++c ) { |
53 | m_view->setColumnHidden( c, true ); |
54 | } |
55 | m_view->setHeaderHidden( true ); |
56 | m_view->setSelectionMode( QAbstractItemView::SingleSelection ); |
57 | m_view->setSelectionBehavior( QAbstractItemView::SelectRows ); |
58 | |
59 | setWidget(m_view); |
60 | |
61 | connect( m_view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()) ); |
62 | } |
63 | |
64 | SchedulesDocker::~SchedulesDocker() |
65 | { |
66 | } |
67 | |
68 | void SchedulesDocker::slotSelectionChanged() |
69 | { |
70 | emit selectionChanged( selectedSchedule() ); |
71 | } |
72 | |
73 | void SchedulesDocker::setProject( Project *project ) |
74 | { |
75 | kDebug(planDbg())<<project; |
76 | m_model.setProject( project ); |
77 | } |
78 | |
79 | ScheduleManager *SchedulesDocker::selectedSchedule() const |
80 | { |
81 | QModelIndexList lst = m_view->selectionModel()->selectedRows(); |
82 | Q_ASSERT( lst.count() <= 1 ); |
83 | ScheduleManager *sm = 0; |
84 | if ( ! lst.isEmpty() ) { |
85 | sm = m_model.manager( m_sfModel.mapToSource( lst.first() ) ); |
86 | } |
87 | return sm; |
88 | } |
89 | |
90 | void SchedulesDocker::setSelectedSchedule( ScheduleManager *sm ) |
91 | { |
92 | qDebug()<<"setSelectedSchedule:" <<sm<<m_model.index( sm ); |
93 | QModelIndex idx = m_sfModel.mapFromSource( m_model.index( sm ) ); |
94 | if ( sm ) { |
95 | Q_ASSERT( idx.isValid() ); |
96 | } |
97 | m_view->selectionModel()->select( idx, QItemSelectionModel::ClearAndSelect ); |
98 | qDebug()<<"setSelectedSchedule:" <<sm<<idx; |
99 | } |
100 | |
101 | //-------------------- |
102 | SchedulesDockerFactory::SchedulesDockerFactory() |
103 | { |
104 | } |
105 | |
106 | QString SchedulesDockerFactory::id() const |
107 | { |
108 | return QString("KPlatoSchedulesDocker" ); |
109 | } |
110 | |
111 | QDockWidget* SchedulesDockerFactory::createDockWidget() |
112 | { |
113 | return new SchedulesDocker(); |
114 | } |
115 | |
116 | } //namespace KPlato |
117 | |
118 | #include "kptschedulesdocker.moc" |
119 | |
120 | |