+#include <SMESHGUI_SpinBox.h>
+
+// Qt incldues
+#include <QItemDelegate>
+#include <QTableWidget>
+#include <QHeaderView>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+
+#define SPACING 6
+
+/*!
+ \brief Sort list of points by ascending order.
+ \internal
+*/
+static void sortData( QList<double>& d )
+{
+ typedef QPair<double, double> Pair;
+ QList<Pair> pairs;
+ for ( int i = 0; i < d.count() / 2; i++ )
+ pairs.append( Pair( d[i*2], d[i*2+1] ) );
+
+ qSort( pairs );
+
+ d.clear();
+
+ Pair p;
+ double prevX = 0.0, prevY = 0.0;
+
+ d.append( prevX );
+ d.append( pairs.count() > 0 ? pairs[0].second : prevY );
+
+ foreach( p, pairs ) {
+ if ( p.first > prevX ) {
+ d.append( p.first );
+ d.append( p.second );
+ prevY = p.second;
+ }
+ prevX = p.first;
+ }
+
+ if ( prevX < 1.0 ) {
+ d.append( 1.0 );
+ d.append( prevY );
+ }
+}
+
+/*!
+ \class StdMeshersGUI_DistrTableFrame::SpinBoxDelegate
+ \brief Custom item delegate (uses double spin box to edit table item)
+ \internal
+*/
+
+class StdMeshersGUI_DistrTableFrame::SpinBoxDelegate : public QItemDelegate
+{
+public:
+ SpinBoxDelegate( StdMeshersGUI_DistrTableFrame::Table* );
+ ~SpinBoxDelegate();
+
+ QWidget* createEditor( QWidget*,
+ const QStyleOptionViewItem&,
+ const QModelIndex& ) const;
+ void setEditorData( QWidget*, const QModelIndex&) const;
+ void setModelData( QWidget*, QAbstractItemModel*,
+ const QModelIndex& ) const;
+ void updateEditorGeometry( QWidget*,
+ const QStyleOptionViewItem&,
+ const QModelIndex& ) const;
+
+private:
+ StdMeshersGUI_DistrTableFrame::Table* myTable;
+};
+
+/*!
+ \class StdMeshersGUI_DistrTableFrame::Table
+ \brief Table function widget
+ \internal
+*/
+
+class StdMeshersGUI_DistrTableFrame::Table : public QTableWidget
+{
+private:
+ struct EditorData
+ {
+ int r, c;
+ SMESHGUI_SpinBox* sb;
+ EditorData() { reset(); }
+ void reset() { r = -1; c = -1; sb = 0; }
+ };
+
+public:
+ Table( QWidget*, int = 2 );
+ ~Table();
+
+ QList<double> data();
+ void setData( const QList<double>& );
+
+ double value( int, int ) const;
+ void setValue( int, int, double );
+
+ double argMinimum( int ) const;
+ double argMaximum( int ) const;
+ double argStep( int ) const;
+ double funcMinimum( int ) const;
+ double funcMaximum( int ) const;
+ double funcStep( int ) const;
+
+ void setFuncMinValue( double );
+
+ QSize sizeHint() const;
+
+ void addRow();
+ void deleteRow();
+
+ void setEditor( int, int, SMESHGUI_SpinBox* );
+
+protected:
+ void closeEditor( QWidget*, QAbstractItemDelegate::EndEditHint );
+
+private:
+ void setUpRows( bool = false );
+ QSize cachedSizeHint() const;
+ void setCachedSizeHint( const QSize& ) const;
+ QList<int> selectedRows();
+
+private:
+ double myFuncMin;
+ QSize myCachedSizeHint;
+ EditorData myEditorData;
+};
+
+// ---
+// StdMeshersGUI_DistrTableFrame::SpinBoxDelegate implementation
+// ---
+
+StdMeshersGUI_DistrTableFrame::SpinBoxDelegate::
+SpinBoxDelegate( StdMeshersGUI_DistrTableFrame::Table* parent )
+ : QItemDelegate( parent ), myTable( parent )