1/* This file is part of the KDE project
2 Copyright (C) 2007, 2012 Dag Andersen danders@get2net>
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 "kptschedulemodel.h"
21
22#include "kptglobal.h"
23#include "kptcommonstrings.h"
24#include "kptcommand.h"
25#include "kptitemmodelbase.h"
26#include "kptduration.h"
27#include "kptnode.h"
28#include "kptproject.h"
29#include "kpttask.h"
30#include "kptresource.h"
31#include "kptschedule.h"
32#include "kptdatetime.h"
33#include "kptschedulerplugin.h"
34#include "kptdebug.h"
35
36#include <KoIcon.h>
37
38#include <QObject>
39#include <QStringList>
40
41
42#include <kglobal.h>
43#include <klocale.h>
44
45
46namespace KPlato
47{
48
49//--------------------------------------
50
51ScheduleModel::ScheduleModel( QObject *parent )
52 : QObject( parent )
53{
54}
55
56ScheduleModel::~ScheduleModel()
57{
58}
59
60const QMetaEnum ScheduleModel::columnMap() const
61{
62 return metaObject()->enumerator( metaObject()->indexOfEnumerator("Properties") );
63}
64
65int ScheduleModel::propertyCount() const
66{
67 return columnMap().keyCount();
68}
69
70//--------------------------------------
71
72ScheduleItemModel::ScheduleItemModel( QObject *parent )
73 : ItemModelBase( parent ),
74 m_manager( 0 ),
75 m_flat( false )
76{
77}
78
79ScheduleItemModel::~ScheduleItemModel()
80{
81}
82
83void ScheduleItemModel::slotScheduleManagerToBeInserted( const ScheduleManager *parent, int row )
84{
85 //kDebug(planDbg())<<parent<<row;
86 if ( m_flat ) {
87 return; // handle in *Inserted();
88 }
89 Q_ASSERT( m_manager == 0 );
90 m_manager = const_cast<ScheduleManager*>(parent);
91 beginInsertRows( index( parent ), row, row );
92}
93
94void ScheduleItemModel::slotScheduleManagerInserted( const ScheduleManager *manager )
95{
96 //kDebug(planDbg())<<manager->name();
97 if ( m_flat ) {
98 int row = m_project->allScheduleManagers().indexOf( const_cast<ScheduleManager*>( manager ) );
99 Q_ASSERT( row >= 0 );
100 beginInsertRows( QModelIndex(), row, row );
101 m_managerlist.insert( row, const_cast<ScheduleManager*>( manager ) );
102 endInsertRows();
103 emit scheduleManagerAdded( const_cast<ScheduleManager*>( manager ) );
104 return;
105 }
106 Q_ASSERT( manager->parentManager() == m_manager );
107 endInsertRows();
108 m_manager = 0;
109 emit scheduleManagerAdded( const_cast<ScheduleManager*>( manager ) );
110}
111
112void ScheduleItemModel::slotScheduleManagerToBeRemoved( const ScheduleManager *manager )
113{
114 //kDebug(planDbg())<<manager->name();
115 if ( m_flat ) {
116 int row = m_managerlist.indexOf( const_cast<ScheduleManager*>( manager ) );
117 beginRemoveRows( QModelIndex(), row, row );
118 m_managerlist.removeAt( row );
119 return;
120 }
121
122 Q_ASSERT( m_manager == 0 );
123 m_manager = const_cast<ScheduleManager*>(manager);
124 QModelIndex i = index( manager );
125 int row = i.row();
126 beginRemoveRows( parent( i ), row, row );
127}
128
129void ScheduleItemModel::slotScheduleManagerRemoved( const ScheduleManager *manager )
130{
131 //kDebug(planDbg())<<manager->name();
132 if ( m_flat ) {
133 endRemoveRows();
134 return;
135 }
136 Q_ASSERT( manager == m_manager ); Q_UNUSED( manager );
137 endRemoveRows();
138 m_manager = 0;
139}
140
141void ScheduleItemModel::slotScheduleManagerToBeMoved( const ScheduleManager *manager )
142{
143 //kDebug(planDbg())<<this<<manager->name()<<"from"<<(manager->parentManager()?manager->parentManager()->name():"project");
144 slotScheduleManagerToBeRemoved( manager );
145}
146
147void ScheduleItemModel::slotScheduleManagerMoved( const ScheduleManager *manager, int index )
148{
149 //kDebug(planDbg())<<this<<manager->name()<<"to"<<manager->parentManager()<<index;
150 slotScheduleManagerRemoved( manager );
151 slotScheduleManagerToBeInserted( manager->parentManager(), index );
152 slotScheduleManagerInserted( manager );
153}
154
155void ScheduleItemModel::slotScheduleToBeInserted( const ScheduleManager *, int /*row*/ )
156{
157}
158
159void ScheduleItemModel::slotScheduleInserted( const MainSchedule * )
160{
161}
162
163void ScheduleItemModel::slotScheduleToBeRemoved( const MainSchedule * )
164{
165}
166
167void ScheduleItemModel::slotScheduleRemoved( const MainSchedule * )
168{
169}
170
171void ScheduleItemModel::setProject( Project *project )
172{
173 if ( m_project ) {
174 disconnect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
175
176 disconnect( m_project, SIGNAL(scheduleManagerToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerToBeInserted(const ScheduleManager*,int)) );
177
178 disconnect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
179
180 disconnect( m_project, SIGNAL(scheduleManagerAdded(const ScheduleManager*)), this, SLOT(slotScheduleManagerInserted(const ScheduleManager*)) );
181
182 disconnect( m_project, SIGNAL(scheduleManagerRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerRemoved(const ScheduleManager*)) );
183
184 disconnect( m_project, SIGNAL(scheduleManagerToBeMoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeMoved(const ScheduleManager*)) );
185
186 disconnect( m_project, SIGNAL(scheduleManagerMoved(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerMoved(const ScheduleManager*,int)) );
187
188 disconnect( m_project, SIGNAL(scheduleChanged(MainSchedule*)), this, SLOT(slotScheduleChanged(MainSchedule*)) );
189
190 disconnect( m_project, SIGNAL(scheduleToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleToBeInserted(const ScheduleManager*,int)) );
191
192 disconnect( m_project, SIGNAL(scheduleToBeRemoved(const MainSchedule*)), this, SLOT(slotScheduleToBeRemoved(const MainSchedule*)) );
193
194 disconnect( m_project, SIGNAL(scheduleAdded(const MainSchedule*)), this, SLOT(slotScheduleInserted(const MainSchedule*)) );
195
196 disconnect( m_project, SIGNAL(scheduleRemoved(const MainSchedule*)), this, SLOT(slotScheduleRemoved(const MainSchedule*)) );
197 }
198 m_project = project;
199 if ( m_project ) {
200 connect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
201
202 connect( m_project, SIGNAL(scheduleManagerToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerToBeInserted(const ScheduleManager*,int)) );
203
204 connect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
205
206 connect( m_project, SIGNAL(scheduleManagerAdded(const ScheduleManager*)), this, SLOT(slotScheduleManagerInserted(const ScheduleManager*)) );
207
208 connect( m_project, SIGNAL(scheduleManagerRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerRemoved(const ScheduleManager*)) );
209
210 connect( m_project, SIGNAL(scheduleManagerToBeMoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeMoved(const ScheduleManager*)) );
211
212 connect( m_project, SIGNAL(scheduleManagerMoved(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerMoved(const ScheduleManager*,int)) );
213
214 connect( m_project, SIGNAL(scheduleChanged(MainSchedule*)), this, SLOT(slotScheduleChanged(MainSchedule*)) );
215
216 connect( m_project, SIGNAL(scheduleToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleToBeInserted(const ScheduleManager*,int)) );
217
218 connect( m_project, SIGNAL(scheduleToBeRemoved(const MainSchedule*)), this, SLOT(slotScheduleToBeRemoved(const MainSchedule*)) );
219
220 connect( m_project, SIGNAL(scheduleAdded(const MainSchedule*)), this, SLOT(slotScheduleInserted(const MainSchedule*)) );
221
222 connect( m_project, SIGNAL(scheduleRemoved(const MainSchedule*)), this, SLOT(slotScheduleRemoved(const MainSchedule*)) );
223 }
224 setFlat( m_flat ); // update m_managerlist
225 reset();
226}
227
228void ScheduleItemModel::slotManagerChanged( ScheduleManager *sch )
229{
230 if ( m_flat ) {
231 int row = m_managerlist.indexOf( sch );
232 emit dataChanged( createIndex( row, 0, sch ), createIndex( row, columnCount() - 1, sch ) );
233 return;
234 }
235
236 int r = sch->parentManager() ? sch->parentManager()->indexOf( sch ) : m_project->indexOf( sch );
237 //kDebug(planDbg())<<sch<<":"<<r;
238 emit dataChanged( createIndex( r, 0, sch ), createIndex( r, columnCount() - 1, sch ) );
239}
240
241
242void ScheduleItemModel::slotScheduleChanged( MainSchedule * )
243{
244}
245
246
247Qt::ItemFlags ScheduleItemModel::flags( const QModelIndex &index ) const
248{
249 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
250 if ( !index.isValid() )
251 return flags;
252 if ( !m_readWrite ) {
253 return flags &= ~Qt::ItemIsEditable;
254 }
255 flags &= ~Qt::ItemIsEditable;
256 ScheduleManager *sm = manager( index );
257 int capabilities = sm->schedulerPlugin()->capabilities();
258 if ( sm && ! sm->isBaselined() ) {
259 switch ( index.column() ) {
260 case ScheduleModel::ScheduleState: break;
261 case ScheduleModel::ScheduleOverbooking:
262 if ( capabilities & SchedulerPlugin::AllowOverbooking &&
263 capabilities & SchedulerPlugin::AvoidOverbooking )
264 {
265 flags |= Qt::ItemIsEditable;
266 }
267 break;
268 case ScheduleModel::ScheduleDirection:
269 if ( sm->parentManager() == 0 &&
270 capabilities & SchedulerPlugin::ScheduleForward &&
271 capabilities & SchedulerPlugin::ScheduleBackward)
272 {
273 flags |= Qt::ItemIsEditable;
274 }
275 break;
276 case ScheduleModel::SchedulePlannedStart: break;
277 case ScheduleModel::SchedulePlannedFinish: break;
278 case ScheduleModel::ScheduleGranularity:
279 if ( ! sm->supportedGranularities().isEmpty() ) {
280 flags |= Qt::ItemIsEditable;
281 }
282 break;
283 default: flags |= Qt::ItemIsEditable; break;
284 }
285 return flags;
286 }
287 return flags;
288}
289
290
291QModelIndex ScheduleItemModel::parent( const QModelIndex &inx ) const
292{
293 if ( !inx.isValid() || m_project == 0 || m_flat ) {
294 return QModelIndex();
295 }
296 //kDebug(planDbg())<<inx.internalPointer()<<":"<<inx.row()<<","<<inx.column();
297 ScheduleManager *sm = manager( inx );
298 if ( sm == 0 ) {
299 return QModelIndex();
300 }
301 return index( sm->parentManager() );
302}
303
304QModelIndex ScheduleItemModel::index( int row, int column, const QModelIndex &parent ) const
305{
306 //kDebug(planDbg())<<m_project<<":"<<row<<","<<column;
307 if ( m_project == 0 || column < 0 || column >= columnCount() || row < 0 || row >= rowCount( parent ) ) {
308 //kDebug(planDbg())<<row<<","<<column<<" out of bounce";
309 return QModelIndex();
310 }
311 if ( m_flat ) {
312 return createIndex( row, column, m_managerlist[ row ] );
313 }
314
315 if ( parent.isValid() ) {
316 return createIndex( row, column, manager( parent )->children().value( row ) );
317 }
318 return createIndex( row, column, m_project->scheduleManagers().value( row ) );
319}
320
321QModelIndex ScheduleItemModel::index( const ScheduleManager *manager ) const
322{
323 if ( m_project == 0 || manager == 0 ) {
324 return QModelIndex();
325 }
326 if ( m_flat ) {
327 return createIndex( m_managerlist.indexOf( const_cast<ScheduleManager*>( manager ) ), 0, const_cast<ScheduleManager*>(manager) );
328 }
329
330 if ( manager->parentManager() == 0 ) {
331 return createIndex( m_project->indexOf( manager ), 0, const_cast<ScheduleManager*>(manager) );
332 }
333 return createIndex( manager->parentManager()->indexOf( manager ), 0, const_cast<ScheduleManager*>(manager) );
334}
335
336int ScheduleItemModel::columnCount( const QModelIndex &/*parent*/ ) const
337{
338 return m_model.propertyCount();
339}
340
341int ScheduleItemModel::rowCount( const QModelIndex &parent ) const
342{
343 if ( m_project == 0 ) {
344 return 0;
345 }
346 if ( m_flat ) {
347 return m_managerlist.count();
348 }
349 if ( !parent.isValid() ) {
350 return m_project->numScheduleManagers();
351 }
352 ScheduleManager *sm = manager( parent );
353 if ( sm ) {
354 //kDebug(planDbg())<<sm->name()<<","<<sm->children().count();
355 return sm->children().count();
356 }
357 return 0;
358}
359
360QVariant ScheduleItemModel::name( const QModelIndex &index, int role ) const
361{
362 ScheduleManager *sm = manager ( index );
363 if ( sm == 0 ) {
364 return QVariant();
365 }
366 switch ( role ) {
367 case Qt::DisplayRole:
368 case Qt::EditRole:
369 case Qt::ToolTipRole:
370 return sm->name();
371 case Qt::StatusTipRole:
372 case Qt::WhatsThisRole:
373 return QVariant();
374 case Qt::DecorationRole:
375 if ( sm->isBaselined() ) {
376 return koIcon("view-time-schedule-baselined");
377 }
378 return QVariant();
379 default:
380 break;
381 }
382 return QVariant();
383}
384
385bool ScheduleItemModel::setName( const QModelIndex &index, const QVariant &value, int role )
386{
387 ScheduleManager *sm = manager ( index );
388 if ( sm == 0 ) {
389 return false;
390 }
391 switch ( role ) {
392 case Qt::EditRole:
393 emit executeCommand( new ModifyScheduleManagerNameCmd( *sm, value.toString(), kundo2_i18n( "Modify schedule name" ) ) );
394 return true;
395 }
396 return false;
397}
398
399QVariant ScheduleItemModel::state( const QModelIndex &index, int role ) const
400{
401 ScheduleManager *sm = manager ( index );
402 if ( sm == 0 ) {
403 return QVariant();
404 }
405 switch ( role ) {
406 case Qt::DisplayRole:
407 {
408 if ( sm->progress() > 0 ) {
409 return sm->progress();
410 }
411 QStringList l = sm->state();
412 if ( l.isEmpty() ) {
413 return "";
414 }
415 return l.first();
416 }
417 case Qt::EditRole:
418 {
419 QStringList l = sm->state();
420 if ( l.isEmpty() ) {
421 return "";
422 }
423 return l.first();
424 }
425 case Qt::ToolTipRole:
426 return sm->state().join(", ");
427 case Qt::TextAlignmentRole:
428 return Qt::AlignCenter;
429 case Qt::StatusTipRole:
430 case Qt::WhatsThisRole:
431 return QVariant();
432 case Role::Maximum:
433 return sm->maxProgress();
434 case Role::Minimum:
435 return 0;
436 }
437 return QVariant();
438}
439
440bool ScheduleItemModel::setState( const QModelIndex &, const QVariant &, int role )
441{
442 switch ( role ) {
443 case Qt::EditRole:
444 return false;
445 }
446 return false;
447}
448
449QVariant ScheduleItemModel::allowOverbooking( const QModelIndex &index, int role ) const
450{
451 ScheduleManager *sm = manager ( index );
452 if ( sm == 0 ) {
453 return QVariant();
454 }
455 int capabilities = sm->schedulerPlugin()->capabilities();
456 switch ( role ) {
457 case Qt::EditRole:
458 return sm->allowOverbooking();
459 case Qt::DisplayRole:
460 if ( capabilities & SchedulerPlugin::AllowOverbooking &&
461 capabilities & SchedulerPlugin::AvoidOverbooking )
462 {
463 return sm->allowOverbooking() ? i18n( "Allow" ) : i18n( "Avoid" );
464 }
465 if ( capabilities & SchedulerPlugin::AllowOverbooking ) {
466 return sm->allowOverbooking() ? i18n( "Allow" ) : i18n( "(Avoid)" );
467 }
468 if ( capabilities & SchedulerPlugin::AvoidOverbooking ) {
469 return sm->allowOverbooking() ? i18n( "(Allow)" ) : i18n( "Avoid" );
470 }
471 break;
472 case Qt::ToolTipRole:
473 if ( capabilities & SchedulerPlugin::AllowOverbooking &&
474 capabilities & SchedulerPlugin::AvoidOverbooking )
475 {
476 return sm->allowOverbooking()
477 ? i18nc( "@info:tooltip", "Allow overbooking resources" )
478 : i18nc( "@info:tooltip", "Avoid overbooking resources" );
479 }
480 if ( capabilities & SchedulerPlugin::AllowOverbooking ) {
481 return sm->allowOverbooking()
482 ? i18nc( "@info:tooltip", "Allow overbooking of resources" )
483 : i18nc( "@info:tooltip 1=scheduler name", "%1 always allows overbooking of resources", sm->schedulerPlugin()->name() );
484 }
485 if ( capabilities & SchedulerPlugin::AvoidOverbooking ) {
486 return sm->allowOverbooking()
487 ? i18nc( "@info:tooltip 1=scheduler name", "%1 always avoids overbooking of resources", sm->schedulerPlugin()->name() )
488 : i18nc( "@info:tooltip", "Avoid overbooking resources" );
489 }
490 break;
491 case Role::EnumList:
492 return QStringList() << i18nc( "@label:listbox", "Avoid" ) << i18nc( "@label:listbox", "Allow" );
493 case Role::EnumListValue:
494 return sm->allowOverbooking() ? 1 : 0;
495 case Qt::TextAlignmentRole:
496 return Qt::AlignCenter;
497 case Qt::StatusTipRole:
498 case Qt::WhatsThisRole:
499 return QVariant();
500 }
501 return QVariant();
502}
503
504bool ScheduleItemModel::setAllowOverbooking( const QModelIndex &index, const QVariant &value, int role )
505{
506 ScheduleManager *sm = manager ( index );
507 if ( sm == 0 ) {
508 return false;
509 }
510 switch ( role ) {
511 case Qt::EditRole:
512 emit executeCommand( new ModifyScheduleManagerAllowOverbookingCmd( *sm, value.toBool(), kundo2_i18n( "Modify allow overbooking" ) ) );
513 return true;
514 }
515 return false;
516}
517
518
519QVariant ScheduleItemModel::usePert( const QModelIndex &index, int role ) const
520{
521 ScheduleManager *sm = manager ( index );
522 if ( sm == 0 ) {
523 return QVariant();
524 }
525 switch ( role ) {
526 case Qt::EditRole:
527 return sm->usePert();
528 case Qt::DisplayRole:
529 return sm->usePert() ? i18n( "PERT" ) : i18n( "None" );
530 case Qt::ToolTipRole:
531 return sm->usePert()
532 ? i18nc( "@info:tooltip", "Use PERT distribution to calculate expected estimate for the tasks" )
533 : i18nc( "@info:tooltip", "Use the tasks expected estimate directly" );
534 case Role::EnumList:
535 return QStringList() << i18nc( "@label:listbox", "None" ) << i18nc( "@label:listbox", "PERT" );
536 case Role::EnumListValue:
537 return sm->usePert() ? 1 : 0;
538 case Qt::TextAlignmentRole:
539 return Qt::AlignCenter;
540 case Qt::StatusTipRole:
541 case Qt::WhatsThisRole:
542 return QVariant();
543 }
544 return QVariant();
545}
546
547bool ScheduleItemModel::setUsePert( const QModelIndex &index, const QVariant &value, int role )
548{
549 ScheduleManager *sm = manager ( index );
550 if ( sm == 0 ) {
551 return false;
552 }
553 switch ( role ) {
554 case Qt::EditRole:
555 emit executeCommand( new ModifyScheduleManagerDistributionCmd( *sm, value.toBool(), kundo2_i18n( "Modify scheduling distribution" ) ) );
556 emit slotManagerChanged( static_cast<ScheduleManager*>( sm ) );
557 return true;
558 }
559 return false;
560}
561
562QVariant ScheduleItemModel::projectStart( const QModelIndex &index, int role ) const
563{
564 if ( m_project == 0 ) {
565 return QVariant();
566 }
567 ScheduleManager *sm = manager ( index );
568 if ( sm == 0 ) {
569 return QVariant();
570 }
571 switch ( role ) {
572 case Qt::DisplayRole:
573 if ( sm->isScheduled() ) {
574 return KGlobal::locale()->formatDateTime( sm->expected()->start() );
575 }
576 break;
577 case Qt::EditRole:
578 if ( sm->isScheduled() ) {
579 return sm->expected()->start();
580 }
581 break;
582 case Qt::ToolTipRole:
583 if ( sm->isScheduled() ) {
584 return i18nc( "@info:tooltip", "Planned start: %1<nl/>Target start: %2", KGlobal::locale()->formatDateTime( sm->expected()->start() ), KGlobal::locale()->formatDateTime( m_project->constraintStartTime() ) );;
585 } else {
586 return i18nc( "@info:tooltip", "Target start: %1", KGlobal::locale()->formatDateTime( m_project->constraintStartTime() ) );;
587 }
588 break;
589 case Qt::TextAlignmentRole:
590 return Qt::AlignCenter;
591 case Qt::StatusTipRole:
592 case Qt::WhatsThisRole:
593 return QVariant();
594 }
595 return QVariant();
596}
597
598QVariant ScheduleItemModel::projectEnd( const QModelIndex &index, int role ) const
599{
600 if ( m_project == 0 ) {
601 return QVariant();
602 }
603 ScheduleManager *sm = manager ( index );
604 if ( sm == 0 ) {
605 return QVariant();
606 }
607 switch ( role ) {
608 case Qt::DisplayRole:
609 if ( sm->isScheduled() ) {
610 return KGlobal::locale()->formatDateTime( sm->expected()->end() );
611 }
612 break;
613 case Qt::EditRole:
614 if ( sm->isScheduled() ) {
615 return sm->expected()->end();
616 }
617 break;
618 case Qt::ToolTipRole:
619 if ( sm->isScheduled() ) {
620 return i18nc( "@info:tooltip", "Planned finish: %1<nl/>Target finish: %2", KGlobal::locale()->formatDateTime( sm->expected()->end() ), KGlobal::locale()->formatDateTime( m_project->constraintEndTime() ) );;
621 } else {
622 return i18nc( "@info:tooltip", "Target finish: %1", KGlobal::locale()->formatDateTime( m_project->constraintEndTime() ) );;
623 }
624 break;
625 case Qt::TextAlignmentRole:
626 return Qt::AlignCenter;
627 case Qt::StatusTipRole:
628 case Qt::WhatsThisRole:
629 return QVariant();
630 }
631 return QVariant();
632}
633
634QVariant ScheduleItemModel::schedulingDirection( const QModelIndex &index, int role ) const
635{
636 ScheduleManager *sm = manager ( index );
637 if ( sm == 0 ) {
638 return QVariant();
639 }
640 int capabilities = sm->schedulerPlugin()->capabilities();
641 switch ( role ) {
642 case Qt::EditRole:
643 return sm->schedulingDirection();
644 case Qt::DisplayRole:
645 if ( capabilities & SchedulerPlugin::ScheduleForward &&
646 capabilities & SchedulerPlugin::ScheduleBackward )
647 {
648 return sm->schedulingDirection() ? i18n( "Backwards" ) : i18n( "Forward" );
649 }
650 if ( capabilities & SchedulerPlugin::ScheduleForward ) {
651 return sm->schedulingDirection() ? i18n( "(Backwards)" ) : i18n( "Forward" );
652 }
653 if ( capabilities & SchedulerPlugin::ScheduleBackward ) {
654 return sm->schedulingDirection() ? i18n( "Backwards" ) : i18n( "(Forward)" );
655 }
656 break;
657 case Qt::ToolTipRole:
658 if ( capabilities & SchedulerPlugin::ScheduleForward &&
659 capabilities & SchedulerPlugin::ScheduleBackward )
660 {
661 return sm->schedulingDirection()
662 ? i18nc( "@info:tooltip", "Schedule project from target end time" )
663 : i18nc( "@info:tooltip", "Schedule project from target start time" );
664 }
665 if ( capabilities & SchedulerPlugin::ScheduleForward ) {
666 return sm->schedulingDirection()
667 ? i18nc( "@info:tooltip 1=scheduler name", "%1 always schedules from target start time", sm->schedulerPlugin()->name() )
668 : i18nc( "@info:tooltip", "Schedule project from target start time" );
669 }
670 if ( capabilities & SchedulerPlugin::ScheduleBackward ) {
671 return sm->schedulingDirection()
672 ? i18nc( "@info:tooltip", "Schedule project from target end time" )
673 : i18nc( "@info:tooltip 1=scheduler name", "%1 always schedules from target end time", sm->schedulerPlugin()->name() );
674 }
675 break;
676 case Role::EnumList:
677 return QStringList() << i18nc( "@label:listbox", "Forward" ) << i18nc( "@label:listbox", "Backwards" );
678 case Role::EnumListValue:
679 return sm->schedulingDirection() ? 1 : 0;
680 case Qt::TextAlignmentRole:
681 return Qt::AlignCenter;
682 case Qt::StatusTipRole:
683 case Qt::WhatsThisRole:
684 return QVariant();
685 }
686 return QVariant();
687}
688
689bool ScheduleItemModel::setSchedulingDirection( const QModelIndex &index, const QVariant &value, int role )
690{
691 ScheduleManager *sm = manager ( index );
692 if ( sm == 0 ) {
693 return false;
694 }
695 switch ( role ) {
696 case Qt::EditRole:
697 emit executeCommand(new ModifyScheduleManagerSchedulingDirectionCmd( *sm, value.toBool(), kundo2_i18n( "Modify scheduling direction" ) ) );
698 emit slotManagerChanged( static_cast<ScheduleManager*>( sm ) );
699 return true;
700 }
701 return false;
702}
703
704QVariant ScheduleItemModel::scheduler( const QModelIndex &index, int role ) const
705{
706 ScheduleManager *sm = manager( index );
707 if ( sm == 0 ) {
708 return QVariant();
709 }
710 SchedulerPlugin *pl = sm->schedulerPlugin();
711 switch ( role ) {
712 case Qt::EditRole:
713 return sm->schedulerPluginId();
714 case Qt::DisplayRole:
715 return pl ? pl->name() : i18n( "Unknown" );
716 case Qt::ToolTipRole:
717 return pl ? pl->comment() : QString();
718 case Role::EnumList:
719 return sm->schedulerPluginNames();
720 case Role::EnumListValue:
721 return sm->schedulerPluginIndex();
722 case Qt::TextAlignmentRole:
723 return Qt::AlignCenter;
724 case Qt::StatusTipRole:
725 return QVariant();
726 case Qt::WhatsThisRole: {
727 QString s = pl->description();
728 return s.isEmpty() ? QVariant() : QVariant( s );
729 }
730 }
731 return QVariant();
732}
733
734bool ScheduleItemModel::setScheduler( const QModelIndex &index, const QVariant &value, int role )
735{
736 ScheduleManager *sm = manager( index );
737 if ( sm != 0 ) {
738 switch ( role ) {
739 case Qt::EditRole: {
740 emit executeCommand( new ModifyScheduleManagerSchedulerCmd( *sm, value.toInt(), kundo2_i18n( "Modify scheduler" ) ) );
741 return true;
742 }
743 }
744 }
745 return false;
746}
747
748QVariant ScheduleItemModel::isScheduled( const QModelIndex &index, int role ) const
749{
750 ScheduleManager *sm = manager( index );
751 if ( sm == 0 ) {
752 return QVariant();
753 }
754 switch ( role ) {
755 case Qt::EditRole:
756 return sm->isScheduled();
757 case Qt::DisplayRole:
758 return sm->isScheduled() ? i18n( "Scheduled" ) : i18n( "Not scheduled" );
759 case Qt::ToolTipRole:
760 break;
761 case Qt::TextAlignmentRole:
762 return Qt::AlignCenter;
763 case Qt::StatusTipRole:
764 case Qt::WhatsThisRole:
765 return QVariant();
766 }
767 return QVariant();
768}
769
770QVariant ScheduleItemModel::granularity(const QModelIndex &index, int role) const
771{
772 ScheduleManager *sm = manager( index );
773 if ( sm == 0 ) {
774 return QVariant();
775 }
776 switch ( role ) {
777 case Qt::EditRole:
778 case Role::EnumListValue:
779 return qMin( sm->granularity(), sm->supportedGranularities().count() - 1 );
780 case Qt::DisplayRole: {
781 QList<long unsigned int> lst = sm->supportedGranularities();
782 if ( lst.isEmpty() ) {
783 return i18nc( "Scheduling granularity not supported", "None" );
784 }
785 int idx = sm->granularity();
786 qulonglong g = idx < lst.count() ? lst[ idx ] : lst.last();
787 return KGlobal::locale()->formatDuration( g );
788 }
789 case Qt::ToolTipRole: {
790 QList<long unsigned int> lst = sm->supportedGranularities();
791 if ( lst.isEmpty() ) {
792 return i18nc( "@info:tooltip", "Scheduling granularity not supported" );
793 }
794 int idx = sm->granularity();
795 qulonglong g = idx < lst.count() ? lst[ idx ] : lst.last();
796 return i18nc( "@info:tooltip", "Selected scheduling granularity: %1", KGlobal::locale()->formatDuration( g ) );
797 }
798 case Qt::TextAlignmentRole:
799 return Qt::AlignRight;
800 case Qt::StatusTipRole:
801 case Qt::WhatsThisRole:
802 return QVariant();
803 case Role::EnumList: {
804 QStringList sl;
805 foreach ( long unsigned int v, sm->supportedGranularities() ) {
806 sl << KGlobal::locale()->formatDuration( v );
807 }
808 return sl;
809 }
810 }
811 return QVariant();
812}
813
814bool ScheduleItemModel::setGranularity( const QModelIndex &index, const QVariant &value, int role )
815{
816 ScheduleManager *sm = manager( index );
817 if ( sm != 0 ) {
818 switch ( role ) {
819 case Qt::EditRole: {
820 emit executeCommand( new ModifyScheduleManagerSchedulingGranularityCmd( *sm, value.toInt(), kundo2_i18n( "Modify scheduling granularity" ) ) );
821 return true;
822 }
823 }
824 }
825 return false;
826}
827
828QVariant ScheduleItemModel::data( const QModelIndex &index, int role ) const
829{
830 //kDebug(planDbg())<<index.row()<<","<<index.column();
831 QVariant result;
832 if ( role == Qt::TextAlignmentRole ) {
833 return headerData( index.column(), Qt::Horizontal, role );
834 }
835 switch ( index.column() ) {
836 case ScheduleModel::ScheduleName: result = name( index, role ); break;
837 case ScheduleModel::ScheduleState: result = state( index, role ); break;
838 case ScheduleModel::ScheduleDirection: result = schedulingDirection( index, role ); break;
839 case ScheduleModel::ScheduleOverbooking: result = allowOverbooking( index, role ); break;
840 case ScheduleModel::ScheduleDistribution: result = usePert( index, role ); break;
841 case ScheduleModel::SchedulePlannedStart: result = projectStart( index, role ); break;
842 case ScheduleModel::SchedulePlannedFinish: result = projectEnd( index, role ); break;
843 case ScheduleModel::ScheduleScheduler: result = scheduler( index, role ); break;
844 case ScheduleModel::ScheduleGranularity: result = granularity( index, role ); break;
845 case ScheduleModel::ScheduleScheduled: result = isScheduled( index, role ); break;
846 default:
847 kDebug(planDbg())<<"data: invalid display value column"<<index.column();
848 return QVariant();
849 }
850 if ( result.isValid() ) {
851 if ( role == Qt::DisplayRole && result.type() == QVariant::String && result.toString().isEmpty()) {
852 // HACK to show focus in empty cells
853 result = ' ';
854 }
855 return result;
856 }
857 return QVariant();
858}
859
860bool ScheduleItemModel::setData( const QModelIndex &index, const QVariant &value, int role )
861{
862 if ( ! index.isValid() ) {
863 return ItemModelBase::setData( index, value, role );
864 }
865 if ( !index.isValid() || ( flags( index ) & Qt::ItemIsEditable ) == 0 || role != Qt::EditRole ) {
866 return false;
867 }
868 switch (index.column()) {
869 case ScheduleModel::ScheduleName: return setName( index, value, role );
870 case ScheduleModel::ScheduleState: return setState( index, value, role );
871 case ScheduleModel::ScheduleDirection: return setSchedulingDirection( index, value, role );
872 case ScheduleModel::ScheduleOverbooking: return setAllowOverbooking( index, value, role );
873 case ScheduleModel::ScheduleDistribution: return setUsePert( index, value, role );
874// case ScheduleModel::ScheduleCalculate: return setCalculateAll( index, value, role );
875 case ScheduleModel::SchedulePlannedStart: return false;
876 case ScheduleModel::SchedulePlannedFinish: return false;
877 case ScheduleModel::ScheduleScheduler: return setScheduler( index, value, role ); break;
878 case ScheduleModel::ScheduleGranularity: return setGranularity( index, value, role );
879 case ScheduleModel::ScheduleScheduled: break;
880 default:
881 qWarning("data: invalid display value column %d", index.column());
882 break;
883 }
884 return false;
885}
886
887QVariant ScheduleItemModel::headerData( int section, Qt::Orientation orientation, int role ) const
888{
889 if ( orientation == Qt::Horizontal ) {
890 if ( role == Qt::DisplayRole ) {
891 switch ( section ) {
892 case ScheduleModel::ScheduleName: return i18n( "Name" );
893 case ScheduleModel::ScheduleState: return i18n( "State" );
894 case ScheduleModel::ScheduleDirection: return i18n( "Direction" );
895 case ScheduleModel::ScheduleOverbooking: return i18n( "Overbooking" );
896 case ScheduleModel::ScheduleDistribution: return i18n( "Distribution" );
897// case ScheduleModel::ScheduleCalculate: return i18n( "Calculate" );
898 case ScheduleModel::SchedulePlannedStart: return i18n( "Planned Start" );
899 case ScheduleModel::SchedulePlannedFinish: return i18n( "Planned Finish" );
900 case ScheduleModel::ScheduleScheduler: return i18n( "Scheduler" );
901 case ScheduleModel::ScheduleGranularity: return i18nc( "title:column", "Granularity" );
902 case ScheduleModel::ScheduleScheduled: return i18n( "Scheduled" );
903 default: return QVariant();
904 }
905 } else if ( role == Qt::TextAlignmentRole ) {
906 return QVariant();
907 }
908 }
909 if ( role == Qt::ToolTipRole ) {
910 switch ( section ) {
911 case ScheduleModel::ScheduleName: return ToolTip::scheduleName();
912 case ScheduleModel::ScheduleState: return ToolTip::scheduleState();
913 case ScheduleModel::ScheduleDirection: return ToolTip::schedulingDirection();
914 case ScheduleModel::ScheduleOverbooking: return ToolTip::scheduleOverbooking();
915 case ScheduleModel::ScheduleDistribution: return ToolTip::scheduleDistribution();
916// case ScheduleModel::ScheduleCalculate: return ToolTip::scheduleCalculate();
917 case ScheduleModel::SchedulePlannedStart: return ToolTip::scheduleStart();
918 case ScheduleModel::SchedulePlannedFinish: return ToolTip::scheduleFinish();
919 case ScheduleModel::ScheduleScheduler: return ToolTip::scheduleScheduler();
920 case ScheduleModel::ScheduleGranularity: return ToolTip::scheduleGranularity();
921 case ScheduleModel::ScheduleScheduled: return QVariant();
922 default: return QVariant();
923 }
924 } else if ( role == Qt::WhatsThisRole ) {
925 switch ( section ) {
926 case ScheduleModel::ScheduleDirection: return WhatsThis::schedulingDirection();
927 case ScheduleModel::ScheduleOverbooking: return WhatsThis::scheduleOverbooking();
928 case ScheduleModel::ScheduleDistribution: return WhatsThis::scheduleDistribution();
929 case ScheduleModel::ScheduleScheduler: return WhatsThis::scheduleScheduler();
930 default: return QVariant();
931 }
932 }
933
934 return ItemModelBase::headerData(section, orientation, role);
935}
936
937QAbstractItemDelegate *ScheduleItemModel::createDelegate( int column, QWidget *parent ) const
938{
939 switch ( column ) {
940 case ScheduleModel::ScheduleState: return new ProgressBarDelegate( parent );
941 case ScheduleModel::ScheduleDirection: return new EnumDelegate( parent );
942 case ScheduleModel::ScheduleOverbooking: return new EnumDelegate( parent );
943 case ScheduleModel::ScheduleDistribution: return new EnumDelegate( parent );
944 case ScheduleModel::ScheduleGranularity: return new EnumDelegate( parent );
945 case ScheduleModel::ScheduleScheduler: return new EnumDelegate( parent );
946 }
947 return 0;
948}
949
950void ScheduleItemModel::sort( int column, Qt::SortOrder order )
951{
952 Q_UNUSED(column);
953 Q_UNUSED(order);
954}
955
956QMimeData * ScheduleItemModel::mimeData( const QModelIndexList & ) const
957{
958 return 0;
959}
960
961QStringList ScheduleItemModel::mimeTypes () const
962{
963 return QStringList();
964}
965
966ScheduleManager *ScheduleItemModel::manager( const QModelIndex &index ) const
967{
968 ScheduleManager *o = 0;
969 if ( index.isValid() && m_project != 0 && index.internalPointer() != 0 && m_project->isScheduleManager( index.internalPointer() ) ) {
970 o = static_cast<ScheduleManager*>( index.internalPointer() );
971 Q_ASSERT( o );
972 }
973 return o;
974}
975
976void ScheduleItemModel::setFlat( bool flat )
977{
978 m_flat = flat;
979 m_managerlist.clear();
980 if ( ! flat || m_project == 0 ) {
981 return;
982 }
983 m_managerlist = m_project->allScheduleManagers();
984}
985
986//--------------------------------------
987ScheduleSortFilterModel::ScheduleSortFilterModel( QObject *parent )
988 : QSortFilterProxyModel( parent )
989{
990}
991
992ScheduleSortFilterModel::~ScheduleSortFilterModel()
993{
994}
995
996ScheduleManager *ScheduleSortFilterModel::manager( const QModelIndex &index ) const
997{
998 QModelIndex i = mapToSource( index );
999 const ScheduleItemModel *m = qobject_cast<const ScheduleItemModel*>( i.model() );
1000 return m == 0 ? 0 : m->manager( i );
1001}
1002
1003//--------------------------------------
1004ScheduleLogItemModel::ScheduleLogItemModel( QObject *parent )
1005 : QStandardItemModel( parent ),
1006 m_project( 0 ),
1007 m_manager( 0 ),
1008 m_schedule( 0 )
1009{
1010}
1011
1012ScheduleLogItemModel::~ScheduleLogItemModel()
1013{
1014}
1015
1016void ScheduleLogItemModel::slotScheduleManagerToBeRemoved( const ScheduleManager *manager )
1017{
1018 if ( m_manager == manager ) {
1019 setManager( 0 );
1020 }
1021}
1022
1023void ScheduleLogItemModel::slotScheduleManagerRemoved( const ScheduleManager *manager )
1024{
1025 kDebug(planDbg())<<manager->name();
1026}
1027
1028void ScheduleLogItemModel::slotScheduleToBeInserted( const ScheduleManager *manager, int row )
1029{
1030 Q_UNUSED(manager);
1031 Q_UNUSED(row);
1032 if ( m_manager && m_manager->expected() /*== ??*/ ) {
1033 //TODO
1034 }
1035}
1036//FIXME remove const on MainSchedule
1037void ScheduleLogItemModel::slotScheduleInserted( const MainSchedule *sch )
1038{
1039 kDebug(planDbg())<<m_schedule<<sch;
1040 if ( m_manager && m_manager == sch->manager() && sch == m_manager->expected() ) {
1041 m_schedule = const_cast<MainSchedule*>( sch );
1042 refresh();
1043 }
1044}
1045
1046void ScheduleLogItemModel::slotScheduleToBeRemoved( const MainSchedule *sch )
1047{
1048 kDebug(planDbg())<<m_schedule<<sch;
1049 if ( m_schedule == sch ) {
1050 m_schedule = 0;
1051 clear();
1052 }
1053}
1054
1055void ScheduleLogItemModel::slotScheduleRemoved( const MainSchedule *sch )
1056{
1057 kDebug(planDbg())<<m_schedule<<sch;
1058}
1059
1060void ScheduleLogItemModel::setProject( Project *project )
1061{
1062 kDebug(planDbg())<<m_project<<"->"<<project;
1063 if ( m_project ) {
1064 disconnect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
1065
1066 disconnect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
1067
1068 disconnect( m_project, SIGNAL(scheduleManagerRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerRemoved(const ScheduleManager*)) );
1069
1070 disconnect( m_project, SIGNAL(scheduleChanged(MainSchedule*)), this, SLOT(slotScheduleChanged(MainSchedule*)) );
1071
1072 disconnect( m_project, SIGNAL(scheduleToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleToBeInserted(const ScheduleManager*,int)) );
1073
1074 disconnect( m_project, SIGNAL(scheduleToBeRemoved(const MainSchedule*)), this, SLOT(slotScheduleToBeRemoved(const MainSchedule*)) );
1075
1076 disconnect( m_project, SIGNAL(scheduleAdded(const MainSchedule*)), this, SLOT(slotScheduleInserted(const MainSchedule*)) );
1077
1078 disconnect( m_project, SIGNAL(scheduleRemoved(const MainSchedule*)), this, SLOT(slotScheduleRemoved(const MainSchedule*)) );
1079 }
1080 m_project = project;
1081 if ( m_project ) {
1082 connect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
1083
1084 connect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
1085
1086 connect( m_project, SIGNAL(scheduleManagerRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerRemoved(const ScheduleManager*)) );
1087
1088 connect( m_project, SIGNAL(scheduleChanged(MainSchedule*)), this, SLOT(slotScheduleChanged(MainSchedule*)) );
1089
1090 connect( m_project, SIGNAL(scheduleToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleToBeInserted(const ScheduleManager*,int)) );
1091
1092 connect( m_project, SIGNAL(scheduleToBeRemoved(const MainSchedule*)), this, SLOT(slotScheduleToBeRemoved(const MainSchedule*)) );
1093
1094 connect( m_project, SIGNAL(scheduleAdded(const MainSchedule*)), this, SLOT(slotScheduleInserted(const MainSchedule*)) );
1095
1096 connect( m_project, SIGNAL(scheduleRemoved(const MainSchedule*)), this, SLOT(slotScheduleRemoved(const MainSchedule*)) );
1097 }
1098}
1099
1100void ScheduleLogItemModel::setManager( ScheduleManager *manager )
1101{
1102 kDebug(planDbg())<<m_manager<<"->"<<manager;
1103 if ( manager != m_manager ) {
1104 if ( m_manager ) {
1105 disconnect( m_manager, SIGNAL(logInserted(MainSchedule*,int,int)), this, SLOT(slotLogInserted(MainSchedule*,int,int)));
1106 }
1107 m_manager = manager;
1108 m_schedule = 0;
1109 clear();
1110 if ( m_manager ) {
1111 m_schedule = m_manager->expected();
1112 refresh();
1113 connect( m_manager, SIGNAL(logInserted(MainSchedule*,int,int)), this, SLOT(slotLogInserted(MainSchedule*,int,int)));
1114 }
1115 }
1116}
1117
1118void ScheduleLogItemModel::slotLogInserted( MainSchedule *s, int firstrow, int lastrow )
1119{
1120 for ( int i = firstrow; i <= lastrow; ++i ) {
1121 addLogEntry( s->logs().value( i ), i + 1 );
1122 }
1123}
1124
1125//FIXME: This only add logs (insert is not used atm)
1126void ScheduleLogItemModel::addLogEntry( const Schedule::Log &log, int /*row*/ )
1127{
1128// kDebug(planDbg())<<log;
1129 QList<QStandardItem*> lst;
1130 if ( log.resource ) {
1131 lst.append( new QStandardItem( log.resource->name() ) );
1132 } else if ( log.node ) {
1133 lst.append( new QStandardItem( log.node->name() ) );
1134 } else {
1135 lst.append( new QStandardItem( "" ) );
1136 }
1137 lst.append( new QStandardItem( m_schedule->logPhase( log.phase ) ) );
1138 QStandardItem *item = new QStandardItem( m_schedule->logSeverity( log.severity ) );
1139 item->setData( log.severity, SeverityRole );
1140 lst.append( item );
1141 lst.append( new QStandardItem( log.message ) );
1142 foreach ( QStandardItem *itm, lst ) {
1143 if ( log.resource ) {
1144 itm->setData( log.resource->id(), IdentityRole );
1145 } else if ( log.node ) {
1146 itm->setData( log.node->id(), IdentityRole );
1147 }
1148 switch ( log.severity ) {
1149 case Schedule::Log::Type_Debug:
1150 itm->setData( Qt::darkYellow, Qt::ForegroundRole );
1151 break;
1152 case Schedule::Log::Type_Info:
1153 break;
1154 case Schedule::Log::Type_Warning:
1155 itm->setData( Qt::blue, Qt::ForegroundRole );
1156 break;
1157 case Schedule::Log::Type_Error:
1158 itm->setData( Qt::red, Qt::ForegroundRole );
1159 break;
1160 default:
1161 break;
1162 }
1163 }
1164 appendRow( lst );
1165// kDebug(planDbg())<<"added:"<<row<<rowCount()<<columnCount();
1166}
1167
1168void ScheduleLogItemModel::refresh()
1169{
1170 clear();
1171 QStringList lst;
1172 lst << i18n( "Name" ) << i18n( "Phase" ) << i18n( "Severity" ) << i18n( "Message" );
1173 setHorizontalHeaderLabels( lst );
1174
1175 if ( m_schedule == 0 ) {
1176 kDebug(planDbg())<<"No main schedule";
1177 return;
1178 }
1179// kDebug(planDbg())<<m_schedule<<m_schedule->logs().count();
1180 int i = 1;
1181 foreach ( const Schedule::Log &l, m_schedule->logs() ) {
1182 addLogEntry( l, i++ );
1183 }
1184}
1185
1186QString ScheduleLogItemModel::identity( const QModelIndex &idx ) const
1187{
1188 QStandardItem *itm = itemFromIndex( idx );
1189 return itm ? itm->data( IdentityRole ).toString() : QString();
1190}
1191
1192void ScheduleLogItemModel::slotManagerChanged( ScheduleManager *manager )
1193{
1194 kDebug(planDbg())<<m_manager<<manager;
1195 if ( m_manager == manager ) {
1196 //TODO
1197// refresh();
1198 }
1199}
1200
1201
1202void ScheduleLogItemModel::slotScheduleChanged( MainSchedule *sch )
1203{
1204 kDebug(planDbg())<<m_schedule<<sch;
1205 if ( m_schedule == sch ) {
1206 refresh();
1207 }
1208}
1209
1210
1211Qt::ItemFlags ScheduleLogItemModel::flags( const QModelIndex &index ) const
1212{
1213 Q_UNUSED(index);
1214 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
1215}
1216
1217} // namespace KPlato
1218
1219#include "kptschedulemodel.moc"
1220