Salome HOME
Table template
authornds <nds@opencascade.com>
Thu, 12 Nov 2015 10:19:01 +0000 (13:19 +0300)
committernds <nds@opencascade.com>
Thu, 12 Nov 2015 10:19:01 +0000 (13:19 +0300)
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_TableModel.cpp [new file with mode: 0755]
src/ModuleBase/ModuleBase_TableModel.h [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetTable.cpp [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetTable.h [new file with mode: 0755]
src/PartSet/PartSet_Module.cpp
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/plugin-Sketch.xml

index 0969deb10369da48d4167659bbead1e36800e8da..2467dcd9832b2d356ef682b0a1e3e395f6329f72 100644 (file)
@@ -33,6 +33,7 @@ SET(PROJECT_HEADERS
   ModuleBase_Preferences.h
   ModuleBase_ResultPrs.h
   ModuleBase_SelectionValidator.h
+  ModuleBase_TableModel.h
   ModuleBase_ToolBox.h
   ModuleBase_Tools.h
   ModuleBase_ViewerFilters.h
@@ -52,6 +53,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetShapeSelector.h
   ModuleBase_WidgetSwitch.h
   ModuleBase_WidgetToolbox.h
+  ModuleBase_WidgetTable.h
   ModuleBase_WidgetValidated.h
   ModuleBase_IconFactory.h
   ModuleBase_WidgetErrorLabel.h
@@ -84,6 +86,7 @@ SET(PROJECT_SOURCES
   ModuleBase_ParamSpinBox.cpp
   ModuleBase_Preferences.cpp
   ModuleBase_ResultPrs.cpp
+  ModuleBase_TableModel.cpp
   ModuleBase_ToolBox.cpp
   ModuleBase_Tools.cpp
   ModuleBase_ViewerFilters.cpp
@@ -103,6 +106,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetShapeSelector.cpp
   ModuleBase_WidgetSwitch.cpp
   ModuleBase_WidgetToolbox.cpp
+  ModuleBase_WidgetTable.cpp
   ModuleBase_WidgetValidated.cpp
   ModuleBase_IconFactory.cpp
   ModuleBase_WidgetErrorLabel.cpp
diff --git a/src/ModuleBase/ModuleBase_TableModel.cpp b/src/ModuleBase/ModuleBase_TableModel.cpp
new file mode 100755 (executable)
index 0000000..9f66fd4
--- /dev/null
@@ -0,0 +1,110 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:      ModuleBase_TableModel.cxx
+// Author:    Natalia ERMOLAEVA
+//
+#include "ModuleBase_TableModel.h"
+
+ModuleBase_TableModel::ModuleBase_TableModel(QObject* theParent)
+: QAbstractTableModel(theParent)
+{
+}
+
+void ModuleBase_TableModel::addRow(const QStringList& theValue)
+{
+  if (theValue.size() != columnCount())
+    return;
+
+  int aRowId = rowCount();
+  for (int i = 0, aCols = columnCount(); i < aCols; i++)
+    myValues.append(Value(aRowId, i, theValue[i].toDouble()));
+
+  emit layoutChanged();
+}
+
+void ModuleBase_TableModel::addRow()
+{
+  return;
+  int aRowId = rowCount();
+  for (int i = 0, aCols = columnCount(); i < aCols; i++)
+    myValues.append(Value(aRowId, i, 0.0));
+
+  emit layoutChanged();
+}
+
+QVariant ModuleBase_TableModel::headerData(int theSection, Qt::Orientation theOrientation,
+                                           int theRole) const
+{
+  if (theSection < myColumnHeaders.size() && theRole == Qt::DisplayRole)
+    return myColumnHeaders[theSection];
+
+  return QAbstractTableModel::headerData(theSection, theOrientation, theRole);
+}
+
+QModelIndex ModuleBase_TableModel::index( int theRow, int theColumn,
+                                         const QModelIndex &theParent) const
+{
+    if (!hasIndex(theRow, theColumn, theParent))
+    return QModelIndex();
+
+  return createIndex(theRow, theColumn);
+}
+
+QVariant ModuleBase_TableModel::data( const QModelIndex& theIndex, int theRole) const
+{
+  QVariant aValue;
+  if (theRole == Qt::DisplayRole) {
+    QList<Value>::const_iterator anIt = myValues.begin(), aLast = myValues.end();
+    for (; anIt != aLast; anIt++) {
+      Value aVal = *anIt;
+      if (aVal.myRow == theIndex.row() && aVal.myColumn == theIndex.column()) {
+        aValue = aVal.myValue;
+        break;
+      }
+    }
+  }
+  else {
+    aValue = QVariant();
+  }
+
+  return aValue;
+}
+
+bool ModuleBase_TableModel::setData( const QModelIndex& theIndex, const QVariant& theValue,
+                                     int theRole)
+{
+  bool isDone = false;
+  if (theRole == Qt::DisplayRole) {
+    QList<Value>::const_iterator anIt = myValues.begin(), aLast = myValues.end();
+    for (; anIt != aLast; anIt++) {
+      Value aVal = *anIt;
+      if (aVal.myRow == theIndex.row() && aVal.myColumn == theIndex.column()) {
+        aVal.myValue = theValue.toDouble();
+        break;
+      }
+    }
+    isDone = true;
+  }
+  else
+    isDone = true;
+  return isDone;
+}
+
+int ModuleBase_TableModel::rowCount( const QModelIndex &theParent) const
+{
+  return myValues.size()/myColumnHeaders.size();
+}
+
+int ModuleBase_TableModel::columnCount( const QModelIndex &theParent) const
+{
+  return myColumnHeaders.size();
+}
+
+Qt::ItemFlags ModuleBase_TableModel::flags(const QModelIndex& theIndex) const
+{
+  if (!theIndex.isValid())
+    return 0;
+  Qt::ItemFlags aFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
+
+  return aFlags;
+}
diff --git a/src/ModuleBase/ModuleBase_TableModel.h b/src/ModuleBase/ModuleBase_TableModel.h
new file mode 100755 (executable)
index 0000000..a554280
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:      ModuleBase_TableModel.h
+// Author:    Natalia ERMOLAEVA
+//
+#ifndef MODULEBASE_TABLE_MODEL_H_
+#define MODULEBASE_TABLE_MODEL_H_
+
+#include "ModuleBase.h"
+
+#include <QAbstractTableModel>
+#include <QStringList>
+
+/**
+  * \ingroup GUI
+  * Enhanced version of the Qt's int spin box.
+  * It allows to store modified state
+*/
+class MODULEBASE_EXPORT ModuleBase_TableModel : public QAbstractTableModel
+{
+  Q_OBJECT
+
+public:
+struct Value {
+  Value(int theRowId, int theColumnId, double theValue)
+    : myRow(theRowId), myColumn(theColumnId), myValue(theValue) {}
+  int myRow;
+  int myColumn;
+  double myValue;
+  };
+
+public:
+  explicit ModuleBase_TableModel(QObject* theParent = 0);
+  virtual ~ModuleBase_TableModel() {};
+
+  void setHeaders(const QStringList& theHeaders) { myColumnHeaders = theHeaders; }
+
+  void addRow(const QStringList& theValue);
+  void addRow();
+
+  virtual QVariant headerData( int theSection, Qt::Orientation theOrientation,
+                               int theRole = Qt::DisplayRole ) const;
+  //--------------------------------------------------------------------------------------
+  virtual QModelIndex index( int theRow, int theColumn,
+                             const QModelIndex &theParent = QModelIndex() ) const;
+  virtual QVariant data( const QModelIndex& theIndex, int theRole = Qt::DisplayRole ) const;
+  virtual bool setData( const QModelIndex& theIndex, const QVariant& theValue,
+                        int theRole = Qt::EditRole );
+
+  //--------------------------------------------------------------------------------------
+  virtual Qt::ItemFlags flags( const QModelIndex &theIndex ) const;
+
+  virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
+  virtual int columnCount( const QModelIndex &theParent = QModelIndex() ) const;
+
+private:
+  QStringList  myColumnHeaders;
+  QList<Value> myValues;
+};
+
+#endif
diff --git a/src/ModuleBase/ModuleBase_WidgetTable.cpp b/src/ModuleBase/ModuleBase_WidgetTable.cpp
new file mode 100755 (executable)
index 0000000..2893d68
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetLabel.cpp
+// Created:     03 Dec 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "ModuleBase_WidgetTable.h"
+
+#include <Config_WidgetAPI.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModuleBase_TableModel.h>
+#include <ModuleBase_Tools.h>
+#include <QTableView>
+
+#include <QLabel>
+#include <QPushButton>
+#include <QGridLayout>
+
+ModuleBase_WidgetTable::ModuleBase_WidgetTable(QWidget* theParent,
+                                               const Config_WidgetAPI* theData,
+                                               const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+  QString aLabel = "Values";
+
+  QStringList aHeaders;
+  aHeaders << "X" << "Y" << "Z";
+
+  QStringList aValues1, aValues2, aValues3;
+
+  aValues1 << "0" << "0" << "0";
+  aValues2 << "0.1" << "0.1" << "0.1";
+  aValues3 << "0.2" << "0.2" << "0.2";
+
+  QGridLayout* aLayout = new QGridLayout(this);
+
+  myTableModel = new ModuleBase_TableModel(theParent);
+  myTableModel->setHeaders(aHeaders);
+  myTableModel->addRow(aValues1);
+  myTableModel->addRow(aValues2);
+  myTableModel->addRow(aValues3);
+
+  myTableView = new QTableView(this);
+  myTableView->setModel(myTableModel);
+
+  QPushButton* anAddBtn = new QPushButton("+", this);
+  QPushButton* aRemBtn = new QPushButton("-", this);
+
+  connect(anAddBtn, SIGNAL(clicked()), this, SLOT(onAddRow()));
+
+  aLayout->addWidget(new QLabel("aLabel"), 0, 0);
+  aLayout->addWidget(anAddBtn, 0, 1);
+  aLayout->addWidget(aRemBtn, 0, 2);
+
+  aLayout->addWidget(myTableView, 1, 0, 1, 3);
+
+  //QVBoxLayout* aLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::zeroMargins(aLayout);
+  //aLayout->addWidget(myLabel);
+  setLayout(aLayout);
+}
+
+ModuleBase_WidgetTable::~ModuleBase_WidgetTable()
+{
+}
+
+QList<QWidget*> ModuleBase_WidgetTable::getControls() const
+{
+  QList<QWidget*> aControls;
+  aControls.append(myTableView);
+  return aControls;
+}
+
+void ModuleBase_WidgetTable::onAddRow()
+{
+  myTableModel->addRow();
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetTable.h b/src/ModuleBase/ModuleBase_WidgetTable.h
new file mode 100755 (executable)
index 0000000..331c195
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_WidgetTable.h
+ *
+ *  Created on: Oct 8, 2014
+ *      Author: sbh
+ */
+
+#ifndef ModuleBase_WidgetTable_H_
+#define ModuleBase_WidgetTable_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+class ModuleBase_TableModel;
+class QTableView;
+
+/**
+* \ingroup GUI
+* Implementation of model widget for line edit widget.
+* It can be defined with "stringvalue" keyword.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetTable : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuration.
+  /// \param theParentId is Id of a parent of the current attribute
+  /// \param thePlaceHolder a string of placeholder
+  ModuleBase_WidgetTable( QWidget* theParent,
+                          const Config_WidgetAPI* theData,
+                          const std::string& theParentId );
+  virtual ~ModuleBase_WidgetTable();
+
+  /// Redefinition of virtual method
+  virtual QList<QWidget*> getControls() const;
+
+protected slots:
+  void onAddRow();
+
+protected:
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom() const { return true;};
+
+  /// Restore value from attribute data to the widget's control
+  virtual bool restoreValueCustom() { return true; }
+
+private:
+  /// A line edit control
+  ModuleBase_TableModel* myTableModel;
+  QTableView*            myTableView;
+};
+
+#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 69d58a916dfc8cf1b39691db64bc5fe660149e3d..6a7977835fd2c195ecaf4046baaccb8246ed5b13 100755 (executable)
@@ -36,6 +36,7 @@
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_WidgetTable.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -511,7 +512,10 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
     aPointWgt->setSketch(mySketchMgr->activeSketch());
     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
     aWgt = aPointWgt;
-  } else if (theType == "sketch-2dpoint_flyout_selector") {
+  }
+  else if (theType == "tablevalue") {
+    aWgt = new ModuleBase_WidgetTable(theParent, theWidgetApi, theParentId);
+  }else if (theType == "sketch-2dpoint_flyout_selector") {
     PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
                                                                  theWidgetApi, theParentId);
     aPointWgt->setSketch(mySketchMgr->activeSketch());
index cf718db760dd812324db95cf16a10a297494b29b..9639cb6bca03cf19b4a403c9e82c89bd2cdaa4b3 100644 (file)
@@ -30,6 +30,9 @@ void SketchPlugin_Point::initAttributes()
   SketchPlugin_SketchEntity::initAttributes();
 
   data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(SketchPlugin_Point::TABLE_ID(), GeomDataAPI_Point2D::typeId());
+
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
index 59995ff4310aeb44edc72c2f950f4d3e09c0c119..88afb276d80b587ab66629cef9debf1c66d7de5b 100644 (file)
@@ -31,6 +31,13 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity
     static const std::string MY_COORD_ID("PointCoordindates");
     return MY_COORD_ID;
   }
+  /// Coordinates of the point
+  inline static const std::string& TABLE_ID()
+  {
+    static const std::string MY_TABLE_ID("TableValue");
+    return MY_TABLE_ID;
+  }
+
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
   {
index a1986c159bced41d5679d563f392655c91257338..d10c08479fe0ca2c7f7ad5eac6b9d89dc2fc669e 100644 (file)
@@ -20,6 +20,7 @@
       <feature id="SketchPoint" title="Point" tooltip="Create point" icon=":icons/point.png">
         <sketch-2dpoint_selector id="PointCoordindates" title="Point" tooltip="Point coordinates"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+        <tablevalue id="TableValue"/>
       </feature>
       <feature id="SketchLine" title="Line" tooltip="Create line" icon=":icons/line.png">
         <sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>