#include "CurveCreator_TableView.h"
#include "CurveCreator_UtilsICurve.hxx"
+#include <gp_Pnt.hxx>
+
#include <QTableWidget>
#include <QTableWidgetItem>
-//#include <QDoubleSpinBox>
+
#include <QtxDoubleSpinBox.h>
const double DBL_MINIMUM = -10000000.;
int aColumnId = theIndex.column();
if ( aColumnId == 2 || aColumnId == 3 ) {
QDoubleSpinBox* aSpin = new QtxDoubleSpinBox( theParent );
- aSpin->setDecimals( 6 );
+ aSpin->setDecimals( 2 );
aSpin->setRange( DBL_MINIMUM, DBL_MAXIMUM );
anEditor = aSpin;
}
void CurveCreator_TableItemDelegate::setEditorData( QWidget* theEditor,
const QModelIndex& theIndex ) const
{
- QTableWidget* aTableWidget = dynamic_cast<QTableWidget*>( parent() );
- QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
- ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
int aColumnId = theIndex.column();
- if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
+ if ( aColumnId == 2 || aColumnId == 3 ) {
QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( theEditor );
- double aValue = anItem->data( Qt::UserRole ).toDouble();
if ( aDblSpin ) {
+ double aValue = theIndex.model()->data( theIndex, Qt::EditRole ).toDouble();
aDblSpin->setValue( aValue );
}
}
QAbstractItemModel* theModel,
const QModelIndex& theIndex ) const
{
- QTableWidget* aTableWidget = dynamic_cast<QTableWidget*>( parent() );
- QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
- ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
-
int aColumnId = theIndex.column();
- if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
+ if ( aColumnId == 2 || aColumnId == 3 ) {
QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( theEditor );
if ( aDblSpin ) {
double aValue = aDblSpin->value();
- anItem->setData( Qt::UserRole, aValue );
+ theModel->setData( theIndex, aValue, Qt::UserRole);
}
}
else
myCurve = theCurve;
}
-void CurveCreator_TableView::addLocalPointToTable( const double theX, const double theY )
+void CurveCreator_TableView::setLocalPointsToTable(
+ const CurveCreator_ICurve::SectionToPointList& thePoints )
{
- CurveCreator_ICurve::SectionToPointList aPoints;
- CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, aPoints );
-
- CurveCreator_ICurve::SectionToPointList aSkipList;
- // table could not contain two equal value rows
- int aRowId = rowCount();
- double aCurrentX, aCurrentY;
- int aSectionId, aPointId;
- CurveCreator_ICurve::SectionToPoint aPoint;
- for ( int i = 0; i < aRowId; i++ ) {
- aCurrentX = item( i, 2 )->data( Qt::UserRole ).toDouble();
- aCurrentY = item( i, 3 )->data( Qt::UserRole ).toDouble();
- if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE &&
- fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) {
- aPoint = std::make_pair<int, int>( getSectionId( i ), getPointId( i ) );
- if ( !CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) )
- aSkipList.push_back( aPoint );
- }
- }
- if ( aSkipList.size() == aPoints.size() )
- return;
+ setRowCount( thePoints.size() );
- QTableWidgetItem* anItem;
- CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(),
- aLast = aPoints.end();
+ int aRowId = 0;
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
+ aLast = thePoints.end();
for ( ; anIt != aLast; anIt++ ) {
- aPoint = *anIt;
- if ( CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) )
- continue;
-
- setRowCount( aRowId+1 );
- aSectionId = aPoint.first;
- aPointId = aPoint.second;
+ CurveCreator_ICurve::SectionToPoint aSPoint = *anIt;
+ int anISection = aSPoint.first;
+ int anIPoint = aSPoint.second;
- anItem = new QTableWidgetItem( myCurve->getSectionName( aSectionId ).c_str() );
+ QTableWidgetItem* anItem;
+ anItem = new QTableWidgetItem( myCurve->getSectionName( anISection ).c_str() );
anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
- anItem->setData( Qt::UserRole, aSectionId );
+ anItem->setData( Qt::UserRole, anISection );
setItem( aRowId, 0, anItem );
- anItem = new QTableWidgetItem( QString::number( aPointId + 1 ) );
+ anItem = new QTableWidgetItem( QString::number( anIPoint + 1 ) );
anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
- anItem->setData( Qt::UserRole, aPointId );
+ anItem->setData( Qt::UserRole, anIPoint );
setItem( aRowId, 1, anItem );
- anItem = new QTableWidgetItem( QString::number( theX ) );
- anItem->setData( Qt::UserRole, theX );
- setItem( aRowId, 2, anItem );
+ gp_Pnt aPoint;
+ CurveCreator_UtilsICurve::getPoint( myCurve, anISection, anIPoint, aPoint );
+
+ anItem = item( aRowId, 2 );
+ if ( !anItem ) {
+ anItem = new QTableWidgetItem();
+ setItem( aRowId, 2, anItem );
+ }
+ anItem->setData( Qt::UserRole, aPoint.X() );
+ anItem->setData( Qt::DisplayRole, QString::number( aPoint.X(), 'f', 2 ) );
+
+ anItem = item( aRowId, 3 );
+ if ( !anItem ) {
+ anItem = new QTableWidgetItem();
+ setItem( aRowId, 3, anItem );
+ }
+ anItem->setData( Qt::UserRole, aPoint.Y() );
+ anItem->setData( Qt::DisplayRole, QString::number( aPoint.Y(), 'f', 2 ) );
- anItem = new QTableWidgetItem( QString::number( theY ) );
- anItem->setData( Qt::UserRole, theY );
- setItem( aRowId, 3, anItem );
+ aRowId++;
}
}