Salome HOME
Synchronize adm files
[modules/paravis.git] / src / Plugins / TableReader / ParaViewPlugin / pqCustomPlotSettingsModel.cxx
old mode 100644 (file)
new mode 100755 (executable)
index f6af9f5..838ec8a
@@ -1,9 +1,9 @@
-// Copyright (C) 2010-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2014  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -31,15 +31,15 @@ class pqCustomPlotSettingsModel::pqImplementation
 {
 public:
   pqImplementation()
-  {
-  }
+{
+}
 
   vtkWeakPointer<vtkSMChartRepresentationProxy> RepresentationProxy;
   QPointer<pqDataRepresentation> Representation;
 };
 
 pqCustomPlotSettingsModel::pqCustomPlotSettingsModel(QObject* parentObject) :
-  Superclass(parentObject), Implementation(new pqImplementation())
+      Superclass(parentObject), Implementation(new pqImplementation())
 {
 }
 
@@ -54,17 +54,17 @@ void pqCustomPlotSettingsModel::setRepresentation(pqDataRepresentation* rep)
   Superclass::setRepresentation(rep);
 
   if (!rep || rep == this->Implementation->Representation)
-    {
+  {
     return;
-    }
+  }
 
   if (this->Implementation->Representation)
-    {
+  {
     QObject::disconnect(this->Implementation->Representation, 0, this, 0);
-    }
+  }
 
   this->Implementation->RepresentationProxy =
-    vtkSMChartRepresentationProxy::SafeDownCast(rep->getProxy());
+      vtkSMChartRepresentationProxy::SafeDownCast(rep->getProxy());
   this->Implementation->Representation = rep;
 }
 
@@ -76,26 +76,26 @@ pqDataRepresentation* pqCustomPlotSettingsModel::representation() const
 
 //-----------------------------------------------------------------------------
 bool pqCustomPlotSettingsModel::setData(const QModelIndex &idx, const QVariant &value,
-                                       int role)
+    int role)
 {
   bool result = false;
   if (idx.isValid() && idx.model() == this)
-    {
+  {
     if (idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
-      {
+    {
       QString name = value.toString();
       if (!name.isEmpty())
-        {
+      {
         this->setSeriesLabel(idx.row(), name);
-        }
       }
+    }
     else if(idx.column() == 0 && role == Qt::CheckStateRole)
-      {
+    {
       result = true;
       int checkstate = value.toInt();
       this->setSeriesEnabled(idx.row(), checkstate == Qt::Checked);
-      }
     }
+  }
   return result;
 }
 
@@ -103,65 +103,65 @@ bool pqCustomPlotSettingsModel::setData(const QModelIndex &idx, const QVariant &
 void pqCustomPlotSettingsModel::setSeriesEnabled(int row, bool enabled)
 {
   if (row >= 0 && row < this->rowCount(QModelIndex()))
+  {
+    int minRow = row;
+    int maxRow = row;
+
+    if (enabled && !(this->IgnoreUnitsModeOn))
     {
-      int minRow = row;
-      int maxRow = row;
-      
-      if (enabled && !(this->IgnoreUnitsModeOn)) 
-       {
-         QString unit = getUnit(QString(this->getSeriesName(row)));
-
-         for (int i = 0; i < rowCount(QModelIndex()); i++)
-           {
-             if (i == row)
-               {
-                 continue;
-               }
-
-             bool rowChanged = false;
-             QString seriesName = QString(this->getSeriesName(i));
-             QString seriesUnit = getUnit(seriesName);
-
-             if ((seriesUnit != unit) && getSeriesEnabled(i))
-               {
-                 vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
-                 "SeriesVisibility").SetStatus(this->getSeriesName(i), 0);
-                 rowChanged = true;
-               }
-             
-             if (!seriesUnit.isEmpty() && this->AutoSelectModeOn &&
-                 (seriesUnit == unit) && !getSeriesEnabled(i))
-               {
-                 vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
-                 "SeriesVisibility").SetStatus(this->getSeriesName(i), 1);
-                 rowChanged = true;
-               }
-             
-             if (rowChanged)
-               {
-                 if (i < minRow)
-                   {
-                     minRow = i;
-                   }
-                 else if (i > maxRow)
-                   {
-                     maxRow = i;
-                   }
-               }
-           }
-       }
-      
-      vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
-      "SeriesVisibility").SetStatus(this->getSeriesName(row), enabled ? 1 : 0);
-      this->Implementation->RepresentationProxy->UpdateVTKObjects();
-    
-      this->setSeriesColor(row, this->getSeriesColor(row));
-      QModelIndex topLeft = this->createIndex(minRow, 0);
-      QModelIndex bottomRight = this->createIndex(maxRow, 0);
-      emit this->dataChanged(topLeft, bottomRight);
-      emit this->redrawChart();
-      this->updateCheckState(0, Qt::Horizontal);
+      QString unit = getUnit(QString(this->getSeriesName(row)));
+
+      for (int i = 0; i < rowCount(QModelIndex()); i++)
+      {
+        if (i == row)
+        {
+          continue;
+        }
+
+        bool rowChanged = false;
+        QString seriesName = QString(this->getSeriesName(i));
+        QString seriesUnit = getUnit(seriesName);
+
+        if ((seriesUnit != unit) && getSeriesEnabled(i))
+        {
+          vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
+              "SeriesVisibility").SetStatus(this->getSeriesName(i), 0);
+          rowChanged = true;
+        }
+
+        if (!seriesUnit.isEmpty() && this->AutoSelectModeOn &&
+            (seriesUnit == unit) && !getSeriesEnabled(i))
+        {
+          vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
+              "SeriesVisibility").SetStatus(this->getSeriesName(i), 1);
+          rowChanged = true;
+        }
+
+        if (rowChanged)
+        {
+          if (i < minRow)
+          {
+            minRow = i;
+          }
+          else if (i > maxRow)
+          {
+            maxRow = i;
+          }
+        }
+      }
     }
+
+    vtkSMPropertyHelper(this->Implementation->RepresentationProxy,
+        "SeriesVisibility").SetStatus(this->getSeriesName(row), enabled ? 1 : 0);
+    this->Implementation->RepresentationProxy->UpdateVTKObjects();
+
+    this->setSeriesColor(row, this->getSeriesColor(row));
+    QModelIndex topLeft = this->createIndex(minRow, 0);
+    QModelIndex bottomRight = this->createIndex(maxRow, 0);
+    emit this->dataChanged(topLeft, bottomRight);
+    emit this->redrawChart();
+    this->updateCheckState(0, Qt::Horizontal);
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -170,15 +170,15 @@ void pqCustomPlotSettingsModel::SetIgnoreUnitsModeOn(bool enabled)
   this->IgnoreUnitsModeOn = enabled;
 
   if (this->IgnoreUnitsModeOn)
-    {
-      this->setCheckable(0, Qt::Horizontal, true);
-      this->setCheckState(0, Qt::Horizontal, Qt::Unchecked);
-    }
+  {
+    this->setCheckable(0, Qt::Horizontal, true);
+    this->setCheckState(0, Qt::Horizontal, Qt::Unchecked);
+  }
   else
-    {
-      this->setCheckState(0, Qt::Horizontal, Qt::Unchecked);
-      this->setCheckable(0, Qt::Horizontal, false);
-    }
+  {
+    this->setCheckState(0, Qt::Horizontal, Qt::Unchecked);
+    this->setCheckable(0, Qt::Horizontal, false);
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -186,33 +186,33 @@ void pqCustomPlotSettingsModel::SetAutoSelectModeOn(bool enabled)
 {
   this->AutoSelectModeOn = enabled;
   if (enabled && !this->IgnoreUnitsModeOn)
+  {
+    for (int i = 0; i < rowCount(QModelIndex()); i++)
     {
-      for (int i = 0; i < rowCount(QModelIndex()); i++)
-       {
-         if (getSeriesEnabled(i))
-           {
-             setSeriesEnabled(i, true);
-             break;
-           }
-       }
+      if (getSeriesEnabled(i))
+      {
+        setSeriesEnabled(i, true);
+        break;
+      }
     }
+  }
 }
 
 //-----------------------------------------------------------------------------
 QString pqCustomPlotSettingsModel::getUnit(const QString& seriesName)
 {
   QString unit("");
-  
+
   int index1 = seriesName.lastIndexOf("]");
   if (index1 == seriesName.size() - 1)
+  {
+    int index2 = seriesName.lastIndexOf(" [");
+    if (index2 > 0)
     {
-      int index2 = seriesName.lastIndexOf(" [");
-      if (index2 > 0)
-       {
-         int start = index2 + 2;
-         unit = seriesName.mid(index2 + 2, index1 - start);
-       }
+      int start = index2 + 2;
+      unit = seriesName.mid(index2 + 2, index1 - start);
     }
+  }
 
   return unit;
 }