Bug 66941 - signal plotter settings dialog - move up and move down buttons don't work
Summary: signal plotter settings dialog - move up and move down buttons don't work
Status: RESOLVED FIXED
Alias: None
Product: ksysguard
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Mandrake RPMs Linux
: HI normal
Target Milestone: ---
Assignee: John Tapsell
URL:
Keywords:
: 126540 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-10-31 00:22 UTC by johnelliottmartin
Modified: 2006-11-28 20:26 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description johnelliottmartin 2003-10-31 00:22:54 UTC
Version:           1.2.0 (using KDE 3.1.3)
Installed from:    Mandrake Linux Cooker i586 - Cooker
Compiler:          gcc version 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)
OS:          Linux (i686) release 2.4.22-10mdkenterprise

In the signal plotter settings dialog, when multiple sensors are being used, on the sensors tab, the move up and move down buttons dont have any effect.
Comment 1 Smart 2004-01-28 09:14:07 UTC
I can see the same.
Ksysguard panel applet, Signal Plotter Settings, Sensors tab. Move up/down have no effect.
QT 3.2.2, KDE 3.1.5, ksysguard 1.2.0
Comment 2 bastian voigt 2004-11-01 10:21:11 UTC
The problem is the following:

void FancyPlotter::applySettings()
{
   [...]
  for ( uint i = 0; i < sensors().count(); ++i ) {
    bool found = false;
    for ( it = list.begin(); it != list.end(); ++it ) {
      if ( (*it)[ 0 ].toInt() == (int)( i + 1 + delCount ) ) {
        mPlotter->beamColors()[ i ] = QColor( (*it)[ 5 ] );
        found = true;
        if ( delCount > 0 )
          (*it)[ 0 ] = QString( "%1" ).arg( i + 1 );
        continue;
      }
    }

As you see the only thing that is changed is the beam color. SO if you moved a sensor up in the list, the only thing that happens is that the upper sensor gets the color of the lower one, but the actual order of the sensors remains unchanged.
Comment 3 bastian voigt 2004-11-01 10:21:38 UTC
BTW, the bug is still present in saturday's CVS version
Comment 4 Greg Martyn 2006-05-26 09:43:25 UTC
See Bug 126540 for a proposed patch
Comment 5 Greg Martyn 2006-05-26 09:44:41 UTC
*** Bug 126540 has been marked as a duplicate of this bug. ***
Comment 6 John Tapsell 2006-11-23 13:41:50 UTC
This still hasn't been applied?
Comment 7 John Tapsell 2006-11-27 02:51:27 UTC
SVN commit 608196 by johnflux:

Fix reordering of sensors.  Thank you Robert Norton for a patch.  Sorry it took so long!

CCBUG:66941


 M  +16 -24    FancyPlotter.cc  
 M  +0 -3      FancyPlotter.h  
 M  +46 -12    FancyPlotterSettings.cc  
 M  +7 -0      FancyPlotterSettings.h  
 M  +14 -0     SensorDisplay.cc  
 M  +1 -0      SensorDisplay.h  
 M  +19 -0     SignalPlotter.cc  
 M  +1 -0      SignalPlotter.h  


--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/FancyPlotter.cc #608195:608196
@@ -31,7 +31,7 @@
 
 #include <ksgrd/SensorManager.h>
 #include <ksgrd/StyleEngine.h>
-
+#include "SensorDisplay.h"
 #include "FancyPlotterSettings.h"
 
 #include "FancyPlotter.h"
@@ -95,7 +95,7 @@
   QValueList< QStringList > list;
   for ( uint i = 0; i < mBeams; ++i ) {
     QStringList entry;
-    entry << QString( "%1" ).arg( i + 1 );
+    entry << QString::number(i);
     entry << sensors().at( i )->hostName();
     entry << KSGRD::SensorMgr->translateSensor( sensors().at( i )->name() );
     entry << KSGRD::SensorMgr->translateUnit( sensors().at( i )->unit() );
@@ -155,33 +155,25 @@
 
   mPlotter->setBackgroundColor( mSettingsDialog->backgroundColor() );
 
-  /* Iterate through registered sensors and through the items of the
-   * listview. Where a sensor cannot be matched, it is removed. */
-  uint delCount = 0;
 
+  QValueList<int> orderOfSensors = mSettingsDialog->order();
+  QValueList<int> deletedSensors = mSettingsDialog->deleted();
+  mSettingsDialog->clearDeleted();
+  mSettingsDialog->resetOrder();
+  QValueList< int >::Iterator itDelete;
+  for ( itDelete = deletedSensors.begin(); itDelete != deletedSensors.end(); ++itDelete )
+    removeSensor(*itDelete);
+
+  QValueList< int >::Iterator itOrder;
+  mPlotter->reorderBeams(orderOfSensors);
+  reorderSensors(orderOfSensors);
+
   QValueList< QStringList > list = mSettingsDialog->sensors();
   QValueList< QStringList >::Iterator it;
 
-  for ( uint i = 0; i < sensors().count(); ++i ) {
-    bool found = false;
-    for ( it = list.begin(); it != list.end(); ++it ) {
-      if ( (*it)[ 0 ].toInt() == (int)( i + 1 + delCount ) ) {
-        mPlotter->beamColors()[ i ] = QColor( (*it)[ 5 ] );
-        found = true;
-        if ( delCount > 0 )
-          (*it)[ 0 ] = QString( "%1" ).arg( i + 1 );
-        continue;
-      }
-    }
+  for ( uint i = 0; i < sensors().count(); ++i )
+        mPlotter->beamColors()[ i ] = QColor( list[i][ 5 ] );
 
-    if ( !found ) {
-      if ( removeSensor(i) ) {
-        i--;
-        delCount++;
-      }
-    }
-  }
-
   mPlotter->repaint();
   setModified( true );
 }
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/FancyPlotter.h #608195:608196
@@ -16,9 +16,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-    KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
-    Please do not commit any changes without consulting me first. Thanks!
-
 */
 
 #ifndef KSG_FANCYPLOTTER_H
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/FancyPlotterSettings.cc #608195:608196
@@ -39,6 +39,7 @@
 #include <qpushbutton.h>
 #include <qradiobutton.h>
 #include <qwhatsthis.h>
+#include <qheader.h>
 
 #include "FancyPlotterSettings.h"
 
@@ -226,11 +227,15 @@
   pageLayout->setRowStretch( 5, 1 );
 
   mSensorView = new KListView( page );
-  mSensorView->addColumn( i18n( "#" ) );
+  mSensorView->addColumn("" , 0);
   mSensorView->addColumn( i18n( "Host" ) );
   mSensorView->addColumn( i18n( "Sensor" ) );
   mSensorView->addColumn( i18n( "Unit" ) );
   mSensorView->addColumn( i18n( "Status" ) );
+  mSensorView->setResizeMode(QListView::LastColumn);
+  mSensorView->header()->setResizeEnabled(false, 0);
+  mSensorView->hideColumn(0);
+  mSensorView->header()->resizeSection(0, 0);
   mSensorView->setAllColumnsShowFocus( true );
   pageLayout->addMultiCellWidget( mSensorView, 0, 5, 0, 0 );
   mSensorView->setSortColumn ( -1 );
@@ -465,7 +470,35 @@
 {
   return mBackgroundColor->color();
 }
+void FancyPlotterSettings::clearDeleted() 
+{
+  mDeleted.clear();
+}
+QValueList<int> FancyPlotterSettings::deleted() const
+{
+  return mDeleted;
+}
 
+QValueList<int> FancyPlotterSettings::order() const
+{
+  QValueList<int> newOrder;
+
+  QListViewItemIterator it( mSensorView );
+  for ( ; it.current(); ++it ) {
+    newOrder.prepend(it.current()->text(0).toInt());
+  }
+  return newOrder;
+}
+
+void FancyPlotterSettings::resetOrder()
+{
+  int i = mSensorView->childCount()-1;
+  QListViewItemIterator it( mSensorView );
+  for ( ; it.current(); ++it, --i) {
+    it.current()->setText(0, QString::number(i));
+  }
+}
+
 void FancyPlotterSettings::setSensors( const QValueList< QStringList > &list )
 {
   mSensorView->clear();
@@ -502,7 +535,7 @@
     QColor color( qRed( rgb ), qGreen( rgb ), qBlue( rgb ) );
     entry << ( color.name() );
 
-    list.append( entry );
+    list.prepend( entry );
   }
 
   return list;
@@ -529,6 +562,10 @@
   QListViewItem* lvi = mSensorView->currentItem();
 
   if ( lvi ) {
+    //Note down the id of the one we are deleting
+    int id = lvi->text(0).toInt();
+    mDeleted.append(id);
+
     /* Before we delete the currently selected item, we determine a
      * new item to be selected. That way we can ensure that multiple
      * items can be deleted without forcing the user to select a new
@@ -546,6 +583,13 @@
 
     delete lvi;
 
+    QListViewItemIterator it( mSensorView );
+    for ( ; it.current(); ++it ) {
+      if(it.current()->text(0).toInt() > id)
+        it.current()->setText(0, QString::number(it.current()->text(0).toInt() -1));
+    }
+
+
     if ( newSelected )
       mSensorView->ensureItemVisible( newSelected );
   }
@@ -566,11 +610,6 @@
       }
     }
 
-    // Re-calculate the "sensor number" field
-    item = mSensorView->firstChild();
-    for ( uint count = 1; item; item = item->itemBelow(), count++ )
-      item->setText( 0, QString( "%1" ).arg( count ) );
-
     selectionChanged( mSensorView->currentItem() );
   }
 }
@@ -581,11 +620,6 @@
     if ( mSensorView->currentItem()->itemBelow() )
       mSensorView->currentItem()->moveItem( mSensorView->currentItem()->itemBelow() );
 
-    // Re-calculate the "sensor number" field
-    QListViewItem* item = mSensorView->firstChild();
-    for ( uint count = 1; item; item = item->itemBelow(), count++ )
-      item->setText( 0, QString( "%1" ).arg( count ) );
-
     selectionChanged( mSensorView->currentItem() );
   }
 }
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/FancyPlotterSettings.h #608195:608196
@@ -97,6 +97,10 @@
 
     void setSensors( const QValueList< QStringList > &list );
     QValueList< QStringList > sensors() const;
+    QValueList<int> order() const;
+    QValueList<int> deleted() const;
+    void clearDeleted();
+    void resetOrder();
 
   private slots:
     void editSensor();
@@ -131,6 +135,9 @@
     QPushButton *mMoveDownButton;
     QRadioButton *mUsePolygonStyle;
     QRadioButton *mUseOriginalStyle;
+
+    /** The numbers of the sensors to be delete.*/
+    QValueList<int> mDeleted;
 };
 
 #endif
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/SensorDisplay.cc #608195:608196
@@ -521,6 +521,20 @@
   return !mFrame;
 }
 
+void SensorDisplay::reorderSensors(const QValueList<int> &orderOfSensors)
+{
+  QPtrList<SensorProperties> newSensors;
+  for ( uint i = 0; i < orderOfSensors.count(); ++i ) {
+    kdDebug() << orderOfSensors[i] << endl;
+    newSensors.append( mSensors.at(orderOfSensors[i] ));
+  }
+
+  mSensors.setAutoDelete( false );
+  mSensors = newSensors;
+  mSensors.setAutoDelete( true );
+}
+
+
 SensorProperties::SensorProperties()
 {
 }
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/SensorDisplay.h #608195:608196
@@ -261,6 +261,7 @@
 //    void setNoFrame( bool value );
     bool noFrame() const;
 
+    void reorderSensors(const QValueList<int> &orderOfSensors);
     QPtrList<SensorProperties> &sensors();
 
   private:
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/SignalPlotter.cc #608195:608196
@@ -126,6 +126,25 @@
   update();
 }
 
+void SignalPlotter::reorderBeams( const QValueList<int>& newOrder )
+{
+  if(newOrder.count() != mBeamData.count()) {
+    kdDebug() << "Serious problem in move sample" << endl;
+    return;
+  }
+  QPtrList<double> newBeamData;
+  QValueList<QColor> newBeamColor;
+
+  for(uint i = 0; i < newOrder.count(); i++) {
+    int newIndex = newOrder[i];
+    newBeamData.append(mBeamData.at(newIndex));
+    newBeamColor.append(*mBeamColor.at(newIndex));
+  }
+  mBeamData = newBeamData;
+  mBeamColor = newBeamColor;
+
+}
+
 void SignalPlotter::changeRange( int beam, double min, double max )
 {
   // Only the first beam affects range calculation.
--- branches/KDE/3.5/kdebase/ksysguard/gui/SensorDisplayLib/SignalPlotter.h #608195:608196
@@ -101,6 +101,7 @@
 
     void setBackgroundColor( const QColor &color );
     QColor backgroundColor() const;
+    void reorderBeams( const QValueList<int>& newOrder );
 
   protected:
     void updateDataBuffers();
Comment 8 Robert Norton 2006-11-27 11:05:21 UTC
Excellent! Glad to be of service...
Comment 9 John Tapsell 2006-11-28 15:36:48 UTC
SVN commit 608821 by johnflux:

For the FancyPlotterSettings widet, Add the apply button again.  Get delete and setcolor buttons working in a different way.
The moveup and movedown buttons are readded, but not working yet

CCBUG:66941


 M  +61 -61    FancyPlotter.cc  
 M  +3 -0      FancyPlotter.h  
 M  +44 -3     FancyPlotterSettings.cc  
 M  +10 -0     FancyPlotterSettings.h  
 M  +12 -0     SensorDisplay.cc  
 M  +1 -0      SensorDisplay.h  
 M  +32 -1     SensorModel.cc  
 M  +6 -0      SensorModel.h  
 M  +36 -3     SignalPlotter.cc  
 M  +1 -0      SignalPlotter.h  
Comment 10 John Tapsell 2006-11-28 20:26:10 UTC
SVN commit 608877 by johnflux:

Move up / move down sensor now works for the fancy plotter.
Inspired by Robert Norton

BUG:66941


 M  +0 -1      FancyPlotter.cc  
 M  +13 -0     FancyPlotterSettings.cc  
 M  +2 -0      FancyPlotterSettings.h  
 M  +0 -1      SensorDisplay.cc  
 M  +29 -2     SensorModel.cc  
 M  +2 -0      SensorModel.h  
 M  +6 -3      SignalPlotter.cc  


--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/FancyPlotter.cc #608876:608877
@@ -172,7 +172,6 @@
     SensorModelEntry::List list = mSettingsDialog->sensors();
 
     for ( int i = 0; i < sensors().count(); ++i ) {
-	  kDebug() << "item " << i << " has id " << list[i].id() << endl;
           mPlotter->beamColors()[ i ] = list[ i ].color();
     }
 
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/FancyPlotterSettings.cc #608876:608877
@@ -310,10 +310,22 @@
 {
 }
 
+void FancyPlotterSettings::moveUpSensor()
+{
+  mModel->moveUpSensor(mView->selectionModel()->currentIndex());
+  selectionChanged(mView->selectionModel()->currentIndex());
+}
+void FancyPlotterSettings::moveDownSensor()
+{
+  mModel->moveDownSensor(mView->selectionModel()->currentIndex());
+  selectionChanged(mView->selectionModel()->currentIndex());
+}
 void FancyPlotterSettings::selectionChanged(const QModelIndex &newCurrent)
 {
   mMoveUpButton->setEnabled(newCurrent.isValid() && newCurrent.row() > 0);
   mMoveDownButton->setEnabled(newCurrent.isValid() && newCurrent.row() < mModel->rowCount() -1 );
+  mEditButton->setEnabled(newCurrent.isValid());
+  mRemoveButton->setEnabled(newCurrent.isValid());
 }
 
 void FancyPlotterSettings::setTitle( const QString &title )
@@ -534,6 +546,7 @@
   if ( !index.isValid() )
     return;
   mModel->removeSensor( index );
+  selectionChanged( mView->selectionModel()->currentIndex() );
 }
 
 void FancyPlotterSettings::clearDeleted()
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/FancyPlotterSettings.h #608876:608877
@@ -106,6 +106,8 @@
     void editSensor();
     void removeSensor();
     void selectionChanged(const QModelIndex &newCurrent);
+    void moveUpSensor();
+    void moveDownSensor();
 
   private:
     KColorButton *mVerticalLinesColor;
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/SensorDisplay.cc #608876:608877
@@ -472,7 +472,6 @@
 {
   QList<SensorProperties *> newSensors;
   for ( uint i = 0; i < orderOfSensors.count(); ++i ) {
-    kDebug() << orderOfSensors[i] << endl;
     newSensors.append( mSensors.at(orderOfSensors[i] ));
   }
   mSensors = newSensors;
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/SensorModel.cc #608876:608877
@@ -125,7 +125,7 @@
   if ( role == Qt::DisplayRole ) {
     switch ( index.column() ) {
       case 0:
-        return QString::number(sensor.id()) + " " +  sensor.hostName();
+        return sensor.hostName();
         break;
       case 1:
         return sensor.sensorName();
@@ -218,11 +218,38 @@
     return;
 
   beginRemoveRows( QModelIndex(), index.row(), index.row());
-    mDeleted.append( mSensors[index.row() ].id());
+    int id = mSensors[index.row() ].id();
+    mDeleted.append(id);
+
     mSensors.removeAt( index.row() );
+    for(int i = 0; i < mSensors.count(); i++) {
+      if(mSensors[i].id() > id) 
+        mSensors[i].setId(mSensors[i].id()-1);
+    }
   endRemoveRows();
+
 }
 
+void SensorModel::moveDownSensor(const QModelIndex &sindex)
+{
+  int row = sindex.row();
+  if(row >= mSensors.count()) return;
+  mSensors.move(row, row+1);
+  
+  for( int i = 0; i < columnCount(); i++)
+    changePersistentIndex(index(row, i), index(row+1, i));
+ 
+  emit dataChanged(sindex, index(row+1, columnCount()-1));
+}
+void SensorModel::moveUpSensor(const QModelIndex &sindex)
+{
+  int row = sindex.row();
+  if(row <= 0) return;
+  mSensors.move(row, row-1);
+  for( int i = 0; i < columnCount(); i++)
+    changePersistentIndex(index(row, i), index(row-1, i));
+  emit dataChanged(sindex, index(row-1, columnCount()-1));
+}
 QList<int> SensorModel::deleted() const
 {
   return mDeleted;
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/SensorModel.h #608876:608877
@@ -73,6 +73,8 @@
     void removeSensor( const QModelIndex &index );
     SensorModelEntry sensor( const QModelIndex &index ) const;
 
+    void moveDownSensor(const QModelIndex &index);
+    void moveUpSensor(const QModelIndex &index);
     void setHasLabel( bool hasLabel );
 
     virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
--- trunk/KDE/kdebase/workspace/ksysguard/gui/SensorDisplayLib/SignalPlotter.cc #608876:608877
@@ -84,6 +84,12 @@
 
 bool KSignalPlotter::addBeam( const QColor &color )
 {
+  QLinkedList< QList<double> >::Iterator it;
+  //When we add a new beam, go back and set the data for this beam to 0 for all the other times. This is because it makes it easier for
+  //moveSensors
+  for(it = mBeamData.begin(); it != mBeamData.end(); ++it) {
+    (*it).append(0);
+  }
   mBeamColors.append(color);
   return true;
 }
@@ -100,7 +106,6 @@
       return;
   }
   mBeamData.prepend(sampleBuf);
-  kDebug() << "AddSample.  New size is " << mBeamData.count() << ".  Just added " << sampleBuf.count() << " samples" <<  endl;
   Q_ASSERT(sampleBuf.count() == mBeamColors.count());
   if(mBeamData.size() > mSamples) {
     mBeamData.removeLast(); // we have too many.  Remove the last item
@@ -141,14 +146,12 @@
   }
   QLinkedList< QList<double> >::Iterator it;
   for(it = mBeamData.begin(); it != mBeamData.end(); ++it) {
-    kDebug() << "beamdata[i] has " << (*it).count() << " and neworder has " << newOrder.count() << endl;
     if(newOrder.count() != (*it).count()) {
       kDebug() << "Serious problem in move sample.  beamdata[i] has " << (*it).count() << " and neworder has " << newOrder.count() << endl;
     } else {
      QList<double> newBeam;
      for(int i = 0; i < newOrder.count(); i++) {
         int newIndex = newOrder[i];
-        kDebug() << "reorderBeams.  " << i << " becomes " << newIndex << endl;
         newBeam.append((*it).at(newIndex));
       }
       (*it) = newBeam;