浏览代码

STYLE: cleanup code to follow CTK style and extensively use Qt functions

Julien Finet 15 年之前
父节点
当前提交
7690d6eea6

+ 33 - 52
Libs/ModuleDescription/ctkModuleDescription.cpp

@@ -33,7 +33,7 @@ ctkModuleDescription::ctkModuleDescription(const ctkModuleDescription &md)
   : QHash<QString, QString>( QHash<QString, QString>( md ) )
 {
   this->ParameterGroups = md.ParameterGroups;
-  this->Logo = md.Logo;
+  this->Icon = md.Icon;
 }
 
 //----------------------------------------------------------------------------
@@ -41,18 +41,20 @@ void ctkModuleDescription::operator=(const ctkModuleDescription &md)
 {
  QHash<QString, QString>::operator=(md);
 	this->ParameterGroups = md.ParameterGroups;
-	this->Logo = md.Logo;
+	this->Icon = md.Icon;
 }
 
 //----------------------------------------------------------------------------
 QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module)
 {
   os << QHash<QString, QString>(module);
-  //os << "Logo: " << module.GetLogo() << endl;
+  //os << "Icon: " << module.icon() << endl;
 
   os << "ParameterGroups: " << endl;
   foreach( const ctkModuleParameterGroup& it, module.parameterGroups())
-  { os << it; }
+    {
+    os << it;
+    }
   return os;
 }
 
@@ -61,24 +63,12 @@ QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module)
 bool ctkModuleDescription::hasReturnParameters() const
 {
   // iterate over each parameter group
-  QVector<ctkModuleParameterGroup>::const_iterator pgbeginit
-    = this->ParameterGroups.begin();
-  QVector<ctkModuleParameterGroup>::const_iterator pgendit
-    = this->ParameterGroups.end();
-  QVector<ctkModuleParameterGroup>::const_iterator pgit;
-  
-  for (pgit = pgbeginit; pgit != pgendit; ++pgit)
+  foreach( const ctkModuleParameterGroup& group, this->ParameterGroups)
     {
     // iterate over each parameter in this group
-    QVector<ctkModuleParameter>::const_iterator pbeginit
-      = (*pgit).parameters().begin();
-    QVector<ctkModuleParameter>::const_iterator pendit
-      = (*pgit).parameters().end();
-    QVector<ctkModuleParameter>::const_iterator pit;
-
-    for (pit = pbeginit; pit != pendit; ++pit)
+    foreach( const ctkModuleParameter& param, group.parameters())
       {
-      if ((*pit).isReturnParameter())
+      if (param.isReturnParameter())
         {
         return true;
         }
@@ -91,12 +81,12 @@ bool ctkModuleDescription::hasReturnParameters() const
 //----------------------------------------------------------------------------
 bool ctkModuleDescription::setParameterDefaultValue(const QString& name, const QString& value)
 {
-  ctkModuleParameter* param = parameter( name );
+  ctkModuleParameter* param = this->parameter( name );
   if ( param )
-  {
+    {
     (*param)[ "Default" ] = value;
     return true;
-  }
+    }
 
   return false;
 }
@@ -129,20 +119,19 @@ ctkModuleParameter* ctkModuleDescription::parameter(const QString& name)
         }
       }    
     }
-
-  return NULL;
+  return 0;
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleDescription ::setLogo(const QIcon& logo)
+void ctkModuleDescription ::setIcon(const QIcon& logo)
 {
-  this->Logo = logo;
+  this->Icon = logo;
 }
 
 //----------------------------------------------------------------------------
-const QIcon& ctkModuleDescription::logo() const
+const QIcon& ctkModuleDescription::icon() const
 {
-  return this->Logo;
+  return this->Icon;
 }
 
 //----------------------------------------------------------------------------
@@ -169,9 +158,9 @@ bool ctkModuleDescription ::readParameterFile(const QString& filename)
     QStringList list = line.split( "=" );
     key = list[ 0 ].trimmed();
     if ( list.size() == 1 )
-    {
+      {
       continue;
-    }
+      }
     value = list[ 1 ].trimmed();
 
     
@@ -207,35 +196,23 @@ writeParameterFile(const QString& filename, bool withHandlesToBulkParameters)
 
   QTextStream in(&rtp);
   // iterate over each parameter group
-  QVector<ctkModuleParameterGroup>::const_iterator pgbeginit
-    = this->ParameterGroups.begin();
-  QVector<ctkModuleParameterGroup>::const_iterator pgendit
-    = this->ParameterGroups.end();
-  QVector<ctkModuleParameterGroup>::const_iterator pgit;
-  
-  for (pgit = pgbeginit; pgit != pgendit; ++pgit)
+  foreach(const ctkModuleParameterGroup& group, this->ParameterGroups)
     {
     // iterate over each parameter in this group
-    QVector<ctkModuleParameter>::const_iterator pbeginit
-      = (*pgit).parameters().begin();
-    QVector<ctkModuleParameter>::const_iterator pendit
-      = (*pgit).parameters().end();
-    QVector<ctkModuleParameter>::const_iterator pit;
-
-    for (pit = pbeginit; pit != pendit; ++pit)
+    foreach(const ctkModuleParameter& param, group.parameters())
       {
       // write out all parameters or just the ones that are not bulk parameters
       if (withHandlesToBulkParameters
           || (!withHandlesToBulkParameters 
-              && ((*pit)[ "Tag" ] != "image"
-                  && (*pit)[ "Tag" ] != "geometry"
-                  && (*pit)[ "Tag" ] != "transform"
-                  && (*pit)[ "Tag" ] != "table"
-                  && (*pit)[ "Tag" ] != "measurement"
-                  && (*pit)[ "Tag" ] != "point"  // point and region are special
-                  && (*pit)[ "Tag" ] != "region")))
+              && (param[ "Tag" ] != "image"
+              && param[ "Tag" ] != "geometry"
+              && param[ "Tag" ] != "transform"
+              && param[ "Tag" ] != "table"
+              && param[ "Tag" ] != "measurement"
+              && param[ "Tag" ] != "point"  // point and region are special
+              && param[ "Tag" ] != "region")))
         {
-        in << (*pit)[ "Name" ] << " = " << (*pit)[ "Default" ] << endl;
+        in << param[ "Name" ] << " = " << param[ "Default" ] << endl;
 
         // multiple="true" may have to be handled differently
         }
@@ -245,21 +222,25 @@ writeParameterFile(const QString& filename, bool withHandlesToBulkParameters)
   return true;
 }
 
+//----------------------------------------------------------------------------
 void ctkModuleDescription::addParameterGroup( const ctkModuleParameterGroup &group )
 {
 	this->ParameterGroups.push_back(group);
 }
 
+//----------------------------------------------------------------------------
 const QVector<ctkModuleParameterGroup>& ctkModuleDescription::parameterGroups() const
 {
 	return this->ParameterGroups;
 }
 
+//----------------------------------------------------------------------------
 QVector<ctkModuleParameterGroup>& ctkModuleDescription::parameterGroups()
 {
 	return this->ParameterGroups;
 }
 
+//----------------------------------------------------------------------------
 void ctkModuleDescription::setParameterGroups( const QVector<ctkModuleParameterGroup>& groups )
 {
 	this->ParameterGroups = groups;

+ 9 - 8
Libs/ModuleDescription/ctkModuleDescription.h

@@ -21,9 +21,12 @@
 #ifndef __ctkModuleDescription_h
 #define __ctkModuleDescription_h
 
-#include "QHash"
-#include "QIcon"
+// Qt includes
+#include <QHash>
+#include <QIcon>
+#include <QVector>
 
+// Module parameter
 #include "ctkModuleParameterGroup.h"
 
 /**
@@ -55,9 +58,8 @@ public:
 
   void operator=(const ctkModuleDescription &md);
 
-  
-  void setLogo(const QIcon& logo);
-  const QIcon& logo() const;
+  void setIcon(const QIcon& logo);
+  const QIcon& icon() const;
   
   void addParameterGroup(const ctkModuleParameterGroup &group);
 
@@ -88,13 +90,12 @@ public:
   /// geometry, etc.) are written to the file.
   bool writeParameterFile(const QString& filename, bool withHandlesToBulkParameters = true);
 
-
 private:
 
   /// Groups of parameters
   QVector<ctkModuleParameterGroup> ParameterGroups;
-  /// Logo
-  QIcon Logo;
+  /// Icon of the module
+  QIcon Icon;
 };
 
 CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module);

+ 4 - 2
Libs/ModuleDescription/ctkModuleDescriptionReader.cpp

@@ -21,24 +21,26 @@ limitations under the License.
 
 #include "ctkModuleDescriptionReader.h"
 
+//----------------------------------------------------------------------------
 ctkModuleDescriptionReader::ctkModuleDescriptionReader() 
 {
 
 }
 
+//----------------------------------------------------------------------------
 ctkModuleDescriptionReader::~ctkModuleDescriptionReader()
 {
 
 }
 
+//----------------------------------------------------------------------------
 void ctkModuleDescriptionReader::setXmlContent( const QString &val )
 {
   this->XmlContent = val;
 }
 
+//----------------------------------------------------------------------------
 const ctkModuleDescription &ctkModuleDescriptionReader::moduleDescription() const
 {
   return this->ModuleDescription;
 }
-
-

+ 0 - 2
Libs/ModuleDescription/ctkModuleDescriptionReader.h

@@ -21,8 +21,6 @@ limitations under the License.
 #ifndef __ctkModuleDescriptionReader_h
 #define __ctkModuleDescriptionReader_h
 
-#include <QString>
-
 #include "CTKModuleDescriptionExport.h"
 #include "ctkModuleDescriptionReaderInterface.h"
 

+ 1 - 3
Libs/ModuleDescription/ctkModuleDescriptionReaderInterface.h

@@ -33,8 +33,6 @@ class CTK_MODULDESC_EXPORT ctkModuleDescriptionReaderInterface : public QObject
 {
     Q_OBJECT
 public:
-  ctkModuleDescriptionReaderInterface(){};
-  ~ctkModuleDescriptionReaderInterface(){};
 
   //! xml is the content of the XML file
   virtual void setXmlContent(const QString &val) = 0;
@@ -43,7 +41,7 @@ public:
   virtual const ctkModuleDescription &moduleDescription() const = 0;
 
   //!
-  virtual void Update( ) = 0;
+  virtual void update( ) = 0;
 
 };
 

+ 12 - 19
Libs/ModuleDescription/ctkModuleParameter.cpp

@@ -21,15 +21,18 @@ limitations under the License.
 #include "ctkModuleParameter.h"
 #include "QStringList"
 
+//----------------------------------------------------------------------------
 ctkModuleParameter::ctkModuleParameter()
 {
 }
 
+//----------------------------------------------------------------------------
 ctkModuleParameter::ctkModuleParameter(const ctkModuleParameter& parameter)
   : QHash<QString, QString>( QHash<QString, QString>( parameter ) )
 {
 }
 
+//----------------------------------------------------------------------------
 bool ctkModuleParameter::isReturnParameter() const
 {
   // could check for tag == float, int, float-vector, ...
@@ -41,11 +44,13 @@ bool ctkModuleParameter::isReturnParameter() const
   return false;
 }
 
+//----------------------------------------------------------------------------
 bool ctkModuleParameter::isFlagParameter() const
 {
   return ((*this)["Flag"] != "" || (*this)[ "LongFlag" ] != "");
 }
 
+//----------------------------------------------------------------------------
 bool ctkModuleParameter::isIndexParameter() const
 {
   return ((*this)[ "Index" ] != "");
@@ -82,33 +87,21 @@ QTextStream & operator<<(QTextStream &os, const ctkModuleParameter &parameter)
 
 //----------------------------------------------------------------------------
 QTextStream & operator<<(QTextStream &os, const QStringList &list)
-{ 
-  QStringList::const_iterator fit;  
-
-  for (fit = list.begin();fit != list.end(); ++fit)
-  {
-    if (fit != list.begin())
-    {
-      os << ", ";
-    }
-    os << (*fit);
-  }
-  os << endl;
-
+{
+  os << list.join(", ") << endl;
   return os;
 }
 
-
 //----------------------------------------------------------------------------
 QTextStream & operator<<(QTextStream &os, const QHash<QString, QString> &hash)
 { 
   QHash<QString,QString>::const_iterator itProp;
   for ( itProp = hash.begin( ) ; 
-    itProp != hash.end( ) ; 
-    itProp++ )
-  {
-    os << QString( itProp.key( ) + ": " + itProp.value( ) ) << endl;
-  }
+        itProp != hash.end( ) ; 
+        itProp++ )
+    {
+    os << itProp.key( ) << ": " << itProp.value( ) << endl;
+    }
 
   return os;
 }

+ 0 - 6
Libs/ModuleDescription/ctkModuleParameter.h

@@ -38,7 +38,6 @@ class CTK_MODULDESC_EXPORT ctkModuleParameter : public QHash<QString, QString>
 {
 public:
   ctkModuleParameter();
-  virtual ~ctkModuleParameter() {}
   ctkModuleParameter(const ctkModuleParameter& parameter);
 
   /// Simple return types are parameters on output channel with no
@@ -51,11 +50,6 @@ public:
   /// Is an index type?
   virtual bool isIndexParameter() const;
 
-protected:
-
-  
-private:
-
 };
 
 CTK_MODULDESC_EXPORT QTextStream & operator<<(QTextStream &os, const ctkModuleParameter &parameter);

+ 14 - 2
Libs/ModuleDescription/ctkModuleParameterGroup.cpp

@@ -20,6 +20,12 @@ limitations under the License.
 
 #include "ctkModuleParameterGroup.h"
 
+//----------------------------------------------------------------------------
+ctkModuleParameterGroup::ctkModuleParameterGroup()
+{
+}
+
+//----------------------------------------------------------------------------
 ctkModuleParameterGroup
 ::ctkModuleParameterGroup(const ctkModuleParameterGroup &parameters)
   : QHash<QString, QString>( QHash<QString, QString>( parameters ) )
@@ -27,29 +33,35 @@ ctkModuleParameterGroup
   this->Parameters = parameters.Parameters;
 }
 
-void
-ctkModuleParameterGroup
+//----------------------------------------------------------------------------
+/* this is done automatically no?
+void ctkModuleParameterGroup
 ::operator=(const ctkModuleParameterGroup &parameters)
 {
   QHash<QString, QString>::operator=(parameters);
   this->Parameters = parameters.Parameters;
 }
+*/
 
+//----------------------------------------------------------------------------
 void ctkModuleParameterGroup::addParameter( const ctkModuleParameter &parameter )
 {
   this->Parameters.push_back(parameter);
 }
 
+//----------------------------------------------------------------------------
 const QVector<ctkModuleParameter>& ctkModuleParameterGroup::parameters() const
 {
   return this->Parameters;
 }
 
+//----------------------------------------------------------------------------
 QVector<ctkModuleParameter>& ctkModuleParameterGroup::parameters()
 {
   return this->Parameters;
 }
 
+//----------------------------------------------------------------------------
 QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group)
 { 
   os << QHash<QString, QString>(group);

+ 2 - 2
Libs/ModuleDescription/ctkModuleParameterGroup.h

@@ -32,10 +32,10 @@
 class CTK_MODULDESC_EXPORT ctkModuleParameterGroup : public QHash<QString, QString>
 {
 public:
-  ctkModuleParameterGroup() {};
+  ctkModuleParameterGroup();
   ctkModuleParameterGroup(const ctkModuleParameterGroup &parameters);
 
-  void operator=(const ctkModuleParameterGroup &parameters);
+  //void operator=(const ctkModuleParameterGroup &parameters);
 
   void addParameter(const ctkModuleParameter &parameter);
 

+ 2 - 2
Plugins/org.commontk.slicermodule/ctkSlicerModuleReader.cxx

@@ -21,8 +21,8 @@ limitations under the License.
 #include "ctkSlicerModuleReader.h"
 #include <QtXml/QDomDocument>
 
-
-void ctkSlicerModuleReader::Update()
+// ----------------------------------------------------------------------------
+void ctkSlicerModuleReader::update()
 {
   QDomDocument domDocument;
   QString errorStr;

+ 1 - 10
Plugins/org.commontk.slicermodule/ctkSlicerModuleReader.h

@@ -21,14 +21,8 @@
 #ifndef __ctkSlicerModuleReader_h
 #define __ctkSlicerModuleReader_h
 
-#include <string>
-
 #include "ctkModuleDescriptionReader.h"
 
-class ModuleDescription;
-class ModuleParameterGroup;
-
-
 /**
  * Reader of Slicer Module XML description
  *
@@ -37,10 +31,7 @@ class ctkSlicerModuleReader : public ctkModuleDescriptionReader
 {
   Q_OBJECT
 public:
-  ctkSlicerModuleReader() {};
-  ~ctkSlicerModuleReader() {};
-
-  void Update( );
+  virtual void update();
 };
 
 #endif