[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kplato/libs
From:       Dag Andersen <danders () get2net ! dk>
Date:       2008-07-14 8:33:38
Message-ID: 1216024418.007237.719.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 832253 by danders:

Show earned value stuff for selected tasks.


 M  +74 -14    models/kptnodechartmodel.cpp  
 M  +13 -1     models/kptnodechartmodel.h  
 M  +74 -52    ui/kpttaskstatusview.cpp  
 M  +31 -8     ui/kpttaskstatusview.h  


--- trunk/koffice/kplato/libs/models/kptnodechartmodel.cpp #832252:832253
@@ -32,38 +32,98 @@
 {
     
 NodeChartModel::NodeChartModel( QObject *parent )
-    : AbstractChartModel( parent )
+    : AbstractChartModel( parent ),
+    m_project( 0 ),
+    m_manager( 0 )
 {
 }
 
+
 void NodeChartModel::setProject( Project *project )
 {
+    m_bcwp.clear();
+    m_acwp.clear();
     if ( m_project ) {
-        m_bcwp.clear();
-        m_acwp.clear();
+        disconnect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), \
this, SLOT( setScheduleManager( ScheduleManager* ) ) ); +        disconnect( \
m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotNodeChanged( Node* ) ) );  \
}  m_project = project;
     if ( m_project ) {
+        connect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), this, \
SLOT( setScheduleManager( ScheduleManager* ) ) ); +        connect( m_project, \
SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotNodeChanged( Node* ) ) );  }
     emit reset();
 }
 
+void NodeChartModel::slotNodeChanged( Node *node )
+{
+    if ( m_nodes.contains( node ) ) {
+        calculate();
+        emit reset();
+        return;
+    }
+    foreach ( Node *n, m_nodes ) {
+        if ( node->isChildOf( n ) ) {
+            calculate();
+            emit reset();
+            return;
+        }
+    }
+}
+
 void NodeChartModel::setScheduleManager( ScheduleManager *sm )
 {
-    if ( m_manager ) {
-        m_bcwp.clear();
-        m_acwp.clear();
-    }
     m_manager = sm;
+    calculate();
+    emit reset();
+}
+
+void NodeChartModel::calculate()
+{
+    //kDebug()<<m_project<<m_manager<<m_nodes;
+    m_bcwp.clear();
+    m_acwp.clear();
     if ( m_manager ) {
         if ( m_project ) {
-            m_bcwp = m_project->bcwpPrDay( sm->id() );
-            m_acwp = m_project->acwp( sm->id() );
+            foreach ( Node *n, m_nodes ) {
+                bool skip = false;
+                foreach ( Node *p, m_nodes ) {
+                    if ( n->isChildOf( p ) ) {
+                        skip = true;
+                        break;
+                    }
+                }
+                if ( ! skip ) {
+                    m_bcwp += n->bcwpPrDay( m_manager->id() );
+                    m_acwp += n->acwp( m_manager->id() );
+                }
+            }
         }
     }
+}
+
+void NodeChartModel::setNodes( const QList<Node*> &nodes )
+{
+    //kDebug()<<nodes;
+    m_nodes = nodes;
+    calculate();
     emit reset();
 }
 
+void NodeChartModel::addNode( Node *node )
+{
+    m_nodes.append( node );
+    calculate();
+    emit reset();
+}
+
+void NodeChartModel::clearNodes()
+{
+    m_nodes.clear();
+    calculate();
+    emit reset();
+}
+
 int NodeChartModel::dataSetCount( const ChartAxisIndex &index ) const
 {
     if ( m_project == 0 || m_manager == 0 ) {
@@ -82,7 +142,7 @@
 
 QVariant NodeChartModel::data( const ChartDataIndex &idx, int role ) const
 {
-    kDebug()<<idx.number()<<idx.userData<<role;
+    //kDebug()<<idx.number()<<idx.userData<<role;
     if ( role == Qt::ForegroundRole ) {
         switch ( idx.userData ) {
             case BCWS: return QColor( Qt::green );
@@ -96,7 +156,7 @@
 QVariant NodeChartModel::data( const ChartDataIndex &idx, const ChartAxisIndex \
&axis, int role ) const  {
     //NOTE: Just return a "day number" for x-axis as the test PlotWidget doesn't \
                handle dates
-    kDebug()<<idx.number()<<idx.userData<<role;
+    //kDebug()<<idx.number()<<idx.userData<<role;
     if ( role == Qt::DisplayRole ) {
         int axisType = axis.userData;
         switch ( idx.userData ) {
@@ -161,15 +221,15 @@
         return ChartDataIndex();
     }
     if ( number == 0 ) {
-        kDebug()<<number<<"BCWS";
+        //kDebug()<<number<<"BCWS";
         return createDataIndex( number, idx, BCWS );
     }
     if ( number == 1 ) {
-        kDebug()<<number<<"BCWP";
+        //kDebug()<<number<<"BCWP";
         return createDataIndex( number, idx, BCWP );
     }
     if ( number == 2 ) {
-        kDebug()<<number<<"ACWP";
+        //kDebug()<<number<<"ACWP";
         return createDataIndex( number, idx, ACWP );
     }
     return ChartDataIndex();
--- trunk/koffice/kplato/libs/models/kptnodechartmodel.h #832252:832253
@@ -31,6 +31,7 @@
     
 class Project;
 class ScheduleManager;
+class Node;
 
 /**
 The NodeChartModel class provides the data interface to chart data.
@@ -47,7 +48,6 @@
     enum UserId { None = 0, BCWS, BCWP, ACWP };
     
     void setProject( Project *project );
-    void setScheduleManager( ScheduleManager *sm );
     
     /// Return the number of data sets that shall be plotted against the axis set @p \
index  virtual int dataSetCount( const ChartAxisIndex &index ) const;
@@ -70,9 +70,21 @@
     const EffortCostMap &bcwp() const { return m_bcwp; }
     const EffortCostMap &acwp() const { return m_acwp; }
     
+    void setNodes( const QList<Node*> &nodes );
+    void addNode( Node *node );
+    void clearNodes();
+    
+public slots:
+    void setScheduleManager( ScheduleManager *sm );
+    void slotNodeChanged( Node *node );
+    
+protected:
+    void calculate();
+    
 private:
     Project *m_project;
     ScheduleManager *m_manager;
+    QList<Node*> m_nodes;
     
     EffortCostMap m_bcwp;
     EffortCostMap m_acwp;
--- trunk/koffice/kplato/libs/ui/kpttaskstatusview.cpp #832252:832253
@@ -43,6 +43,7 @@
 #include <QTextCharFormat>
 #include <QTextTableCell>
 #include <QLineEdit>
+#include <QItemSelection>
 
 #include <kicon.h>
 #include <kaction.h>
@@ -682,8 +683,15 @@
 {
     setupUi( this );
     plotwidget->setAntialiasing(false);
+    connect( &m_model, SIGNAL( reset() ), SLOT( slotReset() ) );
 }
 
+void PerformanceStatusBase::slotReset()
+{
+    //kDebug();
+    draw();
+}
+
 void PerformanceStatusBase::setScheduleManager( ScheduleManager *sm )
 {
     //kDebug();
@@ -693,16 +701,8 @@
 
 void PerformanceStatusBase::setProject( Project *project )
 {
-    if ( m_project ) {
-        disconnect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), \
                this, SLOT( slotUpdate( ScheduleManager* ) ) );
-        disconnect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( \
                slotUpdate() ) );
-    }
     m_project = project;
     m_model.setProject( project );
-    if ( m_project ) {
-        connect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), this, \
                SLOT( slotUpdate( ScheduleManager* ) ) );
-        connect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotUpdate() \
                ) );
-    }
 }
 
 void PerformanceStatusBase::draw()
@@ -743,7 +743,7 @@
 
 void PerformanceStatusBase::drawPlot( Project &p, ScheduleManager &sm ) 
 {
-    kDebug();
+    //kDebug();
     plotwidget->resetPlot();
     int axisCount = m_model.axisCount();
     for ( int i = 0; i < axisCount; ++i ) {
@@ -759,7 +759,7 @@
 
 void PerformanceStatusBase::drawAxis( const ChartAxisIndex &idx ) 
 {
-    kDebug();
+    //kDebug();
     int axisCount = m_model.axisCount( idx );
     QList<double> range;
     for ( int i = 0; i < axisCount; ++i ) {
@@ -779,14 +779,12 @@
 
 void PerformanceStatusBase::drawData( const ChartAxisIndex &axisSet ) 
 {
-    kDebug();
+    //kDebug();
     int dataCount = m_model.dataSetCount( axisSet );
     for ( int i = 0; i < dataCount; ++i ) {
-        kDebug()<<"create data index";
         ChartDataIndex di = m_model.index( i, axisSet );
-        kDebug()<<"created data index:"<<di.number()<<di.userData;
         if ( ! di.isValid() ) {
-            kDebug()<<"Invalid index";
+            //kDebug()<<"Invalid index";
             continue;
         }
         if ( m_model.hasChildren( di ) ) {
@@ -797,7 +795,7 @@
                 drawData( cidx, axisSet );
             }
         } else {
-            kDebug()<<"no sections, go direct to data";
+            //kDebug()<<"no sections, go direct to data";
             drawData( di, axisSet );
         }
     }
@@ -805,42 +803,95 @@
 
 void PerformanceStatusBase::drawData( const ChartDataIndex &index, const \
ChartAxisIndex &axisSet )   {
-    kDebug()<<index.number()<<index.userData;
+    //kDebug()<<index.number()<<index.userData;
     QVariantList data;
     int axisCount = m_model.axisCount( axisSet );
     for ( int j = 0; j < axisCount; ++j ) {
         ChartAxisIndex axis = m_model.axisIndex( j, axisSet );
         if ( m_model.hasAxisChildren( axis ) ) {
-            kDebug()<<"multiple axis";
+            //kDebug()<<"multiple axis";
         } else {
             data << m_model.data( index, axis );
         }
     }
-    kDebug()<<data;
+    //kDebug()<<data;
     Q_ASSERT( data.count() == 2 );
     QVariantList x = data[0].toList();
     QVariantList y = data[1].toList();
     QVariant color = m_model.data( index, Qt::ForegroundRole );
     KPlotObject *kpo = new KPlotObject( color.value<QColor>(), KPlotObject::Lines, 4 \
);  for (int i = 0; i < y.count(); ++i ) {
-        kDebug()<<"Add point:"<<x[i].toInt() << y[i].toDouble();
+        //kDebug()<<"Add point:"<<x[i].toInt() << y[i].toDouble();
         kpo->addPoint( x[i].toInt(), y[i].toDouble() );
     }
     plotwidget->addPlotObject( kpo );
 }
 
+//-----------------------------------
+PerformanceStatusTreeView::PerformanceStatusTreeView( QWidget *parent )
+    : QSplitter( parent )
+{
+    m_tree = new TreeViewBase( this );
+    NodeItemModel *m = new NodeItemModel( m_tree );
+    m_tree->setModel( m );
+    QList<int> lst1; lst1 << 1 << -1; // only display column 0 (NodeName) in tree \
view +    m_tree->setDefaultColumns( QList<int>() << 0 );
+    m_tree->setColumnsHidden( lst1 );
+    m_tree->setSelectionMode( QAbstractItemView::ExtendedSelection );
+    addWidget( m_tree );
+    
+    m_chart = new PerformanceStatusBase( this );
+    addWidget( m_chart );
+    
+    connect( m_tree->selectionModel(), SIGNAL( selectionChanged( const \
QItemSelection &, const QItemSelection & ) ), SLOT( slotSelectionChanged( const \
QItemSelection &, const QItemSelection & ) ) ); +}
 
+void PerformanceStatusTreeView::slotSelectionChanged( const QItemSelection&, const \
QItemSelection& ) +{
+    //kDebug();
+    QList<Node*> nodes;
+    foreach ( const QModelIndex &i, m_tree->selectionModel()->selectedIndexes() ) {
+        Node *n = nodeModel()->node( i );
+        if ( ! nodes.contains( n ) ) {
+            nodes.append( n );
+        }
+    }
+    m_chart->model()->setNodes( nodes );
+}
+
+void PerformanceStatusTreeView::draw()
+{
+    m_chart->draw();
+}
+
+NodeItemModel *PerformanceStatusTreeView::nodeModel() const
+{
+    return static_cast<NodeItemModel*>( m_tree->model() );
+}
+
+void PerformanceStatusTreeView::setScheduleManager( ScheduleManager *sm )
+{
+    nodeModel()->setManager( sm );
+    m_chart->setScheduleManager( sm );
+}
+
+void PerformanceStatusTreeView::setProject( Project *project )
+{
+    nodeModel()->setProject( project );
+    m_chart->setProject( project );
+}
+
+
 //-----------------------------------
 PerformanceStatusView::PerformanceStatusView( KoDocument *part, QWidget *parent )
-    : ViewBase( part, parent ),
-    m_project( 0 ),
-    m_manager( 0 )
+    : ViewBase( part, parent )
 {
     kDebug()<<"-------------------- creating PerformanceStatusView \
-------------------";  QVBoxLayout * l = new QVBoxLayout( this );
     l->setMargin( 0 );
-    m_view = new PerformanceStatusBase( this );
+    m_view = new PerformanceStatusTreeView( this );
     l->addWidget( m_view );
+    
     setupGui();
 
 }
@@ -848,37 +899,14 @@
 void PerformanceStatusView::setScheduleManager( ScheduleManager *sm )
 {
     //kDebug();
-    m_manager = sm;
     m_view->setScheduleManager( sm );
-    draw();
 }
 
 void PerformanceStatusView::setProject( Project *project )
 {
-    if ( m_project ) {
-        disconnect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), \
                this, SLOT( slotUpdate( ScheduleManager* ) ) );
-        disconnect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( \
                slotUpdate() ) );
-    }
-    m_project = project;
-    if ( m_project ) {
-        connect( m_project, SIGNAL( projectCalculated( ScheduleManager* ) ), this, \
                SLOT( slotUpdate( ScheduleManager* ) ) );
-        connect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotUpdate() \
                ) );
-    }
     m_view->setProject( project );
 }
 
-void PerformanceStatusView::slotUpdate()
-{
-    draw();
-}
-
-void PerformanceStatusView::slotUpdate( ScheduleManager *sm )
-{
-    if ( sm == m_manager ) {
-        slotUpdate();
-    }
-}
-
 void PerformanceStatusView::draw()
 {
     m_view->draw();
@@ -899,12 +927,6 @@
     addContextAction( actionOptions );*/
 }
 
-void PerformanceStatusView::slotSplitView()
-{
-    kDebug();
-}
-
-
 void PerformanceStatusView::slotOptions()
 {
     kDebug();
--- trunk/koffice/kplato/libs/ui/kpttaskstatusview.h #832252:832253
@@ -30,7 +30,10 @@
 #include "ui_kptperformancestatus.h"
 #include "kptnodechartmodel.h"
 
+#include <QSplitter>
+
 class QTextBrowser;
+class QItemSelection;
 
 class KoDocument;
 
@@ -44,6 +47,7 @@
 class Task;
 class ScheduleManager;
 class TaskStatusItemModel;
+class NodeItemModel;
 
 typedef QList<Node*> NodeList;
 
@@ -205,7 +209,7 @@
 //----------------------------------
 class PerformanceStatusBase : public QWidget, public Ui::PerformanceStatus
 {
-
+    Q_OBJECT
 public:
     explicit PerformanceStatusBase( QWidget *parent );
     
@@ -213,6 +217,7 @@
     void setScheduleManager( ScheduleManager *sm );
 
     void draw();
+    NodeChartModel *model() const { return const_cast<NodeChartModel*>( &m_model ); \
}  
 protected:
     void drawValues();
@@ -221,6 +226,9 @@
     void drawData( const ChartAxisIndex &idx );
     void drawData( const ChartDataIndex &index, const ChartAxisIndex &axisSet );
 
+protected slots:
+    void slotReset();
+    
 private:
     Project *m_project;
     ScheduleManager *m_manager;
@@ -228,6 +236,27 @@
 };
 
 //----------------------------------
+class PerformanceStatusTreeView : public QSplitter
+{
+    Q_OBJECT
+public:
+    explicit PerformanceStatusTreeView( QWidget *parent );
+
+    NodeItemModel *nodeModel() const;
+    void setProject( Project *project );
+    void setScheduleManager( ScheduleManager *sm );
+    void draw();
+
+protected slots:
+    void slotSelectionChanged( const QItemSelection & selected, const QItemSelection \
& deselected ); +    
+private:
+    TreeViewBase *m_tree;
+    PerformanceStatusBase *m_chart;
+};
+
+
+//----------------------------------
 class KPLATOUI_EXPORT PerformanceStatusView : public ViewBase
 {
     Q_OBJECT
@@ -251,20 +280,14 @@
 
     void setScheduleManager( ScheduleManager *sm );
 
-    void slotUpdate();
-    void slotUpdate( ScheduleManager *sm );
-
 protected:
     void updateActionsEnabled( bool on );
 
 private slots:
-    void slotSplitView();
     void slotOptions();
 
 private:
-    Project *m_project;
-    ScheduleManager *m_manager;
-    PerformanceStatusBase *m_view;
+    PerformanceStatusTreeView *m_view;
 
     // View options context menu
     KAction *actionOptions;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic