From 884f91609308b39d612aa192e4f725a49056d95d Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 8 Apr 2013 13:17:04 +0000 Subject: [PATCH] The table interface creation in order to have a possibility to use in TableViewer any table realization - QTableWidget or QTableView. --- src/Qtx/QtxTable.cxx | 170 ++++++++++++++++++--- src/Qtx/QtxTable.h | 21 ++- src/Qtx/QtxTableInterface.h | 119 +++++++++++++++ src/TableViewer/TableViewer_ViewModel.cxx | 5 +- src/TableViewer/TableViewer_ViewWindow.cxx | 153 +++++++------------ src/TableViewer/TableViewer_ViewWindow.h | 24 +-- 6 files changed, 357 insertions(+), 135 deletions(-) create mode 100644 src/Qtx/QtxTableInterface.h diff --git a/src/Qtx/QtxTable.cxx b/src/Qtx/QtxTable.cxx index cc42a9e9c..8779420ad 100644 --- a/src/Qtx/QtxTable.cxx +++ b/src/Qtx/QtxTable.cxx @@ -644,6 +644,22 @@ QtxTable::~QtxTable() //delete myStyleWrapper; } +/*! + Returns a table row count + */ +int QtxTable::rowCount() const +{ + return QTableWidget::rowCount(); +} + +/** + * Returns a table column count + */ +int QtxTable::columnCount() const +{ + return QTableWidget::columnCount(); +} + bool QtxTable::isSelectAllEnabled() const { return true;//mySelectAll; @@ -1127,19 +1143,29 @@ void QtxTable::setNumHeaders( const Qt::Orientation o, const int n ) */ } -QVariant QtxTable::headerData( const Qt::Orientation o, const int section, const int role ) const +/* Returns a table header value + * @param theSection + * a header section + * @param theOrientation + * a horizontal or vertical orientation + * @param theRole + * a type of modification, that should be applyed to table + */ +QVariant QtxTable::headerData( const int theSection, + const Qt::Orientation theOrientation, + const int theRole ) const { - QVariant res; + QVariant aRes; if ( model() ) - res = model()->headerData( section, o, role ); - return res; + aRes = model()->headerData( theSection, theOrientation, theRole ); + return aRes; } QFont QtxTable::headerFont( const Qt::Orientation o, const int section ) const { QFont res = o == Qt::Horizontal ? horizontalHeader()->font() : verticalHeader()->font(); - QVariant aVar = headerData( o, section, Qt::FontRole ); + QVariant aVar = headerData( section, o, Qt::FontRole ); if ( aVar.isValid() && aVar.canConvert( QVariant::Font ) ) res = aVar.value(); return res; @@ -1148,7 +1174,7 @@ QFont QtxTable::headerFont( const Qt::Orientation o, const int section ) const QColor QtxTable::headerForeground( const Qt::Orientation o, const int section ) const { QColor res; - QVariant aVar = headerData( o, section, Qt::ForegroundRole ); + QVariant aVar = headerData( section, o, Qt::ForegroundRole ); if ( aVar.isValid() && aVar.canConvert( QVariant::Color ) ) res = aVar.value(); return res; @@ -1157,7 +1183,7 @@ QColor QtxTable::headerForeground( const Qt::Orientation o, const int section ) QColor QtxTable::headerBackground( const Qt::Orientation o, const int section ) const { QColor res; - QVariant aVar = headerData( o, section, Qt::BackgroundRole ); + QVariant aVar = headerData( section, o, Qt::BackgroundRole ); if ( aVar.isValid() && aVar.canConvert( QVariant::Color ) ) res = aVar.value(); return res; @@ -1166,51 +1192,95 @@ QColor QtxTable::headerBackground( const Qt::Orientation o, const int section ) QIcon QtxTable::headerIcon( const Qt::Orientation o, const int section ) const { QIcon res; - QVariant aVar = headerData( o, section, Qt::DecorationRole ); + QVariant aVar = headerData( section, o, Qt::DecorationRole ); if ( aVar.isValid() && aVar.canConvert( QVariant::Icon ) ) res = aVar.value(); return res; } -void QtxTable::setHeaderData( const Qt::Orientation o, const int section, const QVariant& var, - const int role ) +/* Sets a table header value + * @param theSection + * a header section + * @param theOrientation + * a horizontal or vertical orientation + * @param theValue + * a value + * @param theRole + * a type of modification, that should be applyed to table + */ +void QtxTable::setHeaderData( const int theSection, + const Qt::Orientation theOrientation, + const QVariant& theValue, + const int theRole ) { QTableWidgetItem* anItem = 0; - if ( o == Qt::Horizontal ) - anItem = horizontalHeaderItem( section ); + if ( theOrientation == Qt::Horizontal ) + anItem = horizontalHeaderItem( theSection ); else - anItem = verticalHeaderItem( section ); + anItem = verticalHeaderItem( theSection ); if ( anItem ) - anItem->setData( role, var ); + anItem->setData( theRole, theValue ); else { anItem = new QTableWidgetItem(); - anItem->setData( role, var ); - if ( o == Qt::Horizontal ) - setHorizontalHeaderItem( section, anItem ); + anItem->setData( theRole, theValue ); + if ( theOrientation == Qt::Horizontal ) + setHorizontalHeaderItem( theSection, anItem ); else - setVerticalHeaderItem( section, anItem ); + setVerticalHeaderItem( theSection, anItem ); } } void QtxTable::setHeaderFont( const Qt::Orientation o, const int section, const QFont& font ) { - setHeaderData( o, section, QVariant( font ), Qt::FontRole ); + setHeaderData( section, o, QVariant( font ), Qt::FontRole ); } void QtxTable::setHeaderForeground( const Qt::Orientation o, const int section, const QColor& c ) { - setHeaderData( o, section, QVariant( c ), Qt::ForegroundRole ); + setHeaderData( section, o, QVariant( c ), Qt::ForegroundRole ); } void QtxTable::setHeaderBackground( const Qt::Orientation o, const int section, const QColor& c ) { - setHeaderData( o, section, QVariant( c ), Qt::BackgroundRole ); + setHeaderData( section, o, QVariant( c ), Qt::BackgroundRole ); } void QtxTable::setHeaderIcon( const Qt::Orientation o, const int section, const QIcon& icon ) { - setHeaderData( o, section, QVariant( icon ), Qt::DecorationRole ); + setHeaderData( section, o, QVariant( icon ), Qt::DecorationRole ); +} + +/*! + * Returns a table cell value + * @param theRow + * a row position + * @param theColumn + * a column position + * @param theRole + * a type of modification, that should be applyed to table + */ +QVariant QtxTable::data( const int theRow, const int theColumn, + const int theRole ) const +{ + QVariant aValue; + switch ( theRole ) { + case Qt::DisplayRole: + aValue = cellData( theRow, theColumn ); + break; + case Qt::FontRole: + aValue = cellFont( theRow, theColumn ); + break; + case Qt::ForegroundRole: + aValue = cellForeground( theRow, theColumn ); + break; + case Qt::BackgroundRole: + aValue = cellBackground( theRow, theColumn ); + break; + default: + break; + } + return aValue; } QVariant QtxTable::cellData( const int row, const int col ) const @@ -1261,6 +1331,52 @@ QIcon QtxTable::cellIcon( const int row, const int col ) const return res; } +/*! + * Set the value into a table cell + * @param theRow + * a row position + * @param theColumn + * a column position + * @param theValue + * a value + * @param theRole + * a type of modification, that should be applyed to table + */ +void QtxTable::setData( const int theRow, const int theColumn, + const QVariant& theValue, const int theRole ) +{ + // to check the best solution: + if ( false ) { + QTableWidgetItem* anItem = getItem( theRow, theColumn ); + if ( anItem ) { + anItem->setData( theRole, theValue ); + } + } + + switch ( theRole ) { + case Qt::DisplayRole: + setCellData( theRow, theColumn, theValue ); + break; + case Qt::FontRole: { + if ( theValue.isValid() && theValue.canConvert( QVariant::Font ) ) + setCellFont( theRow, theColumn, theValue.value() ); + } + break; + case Qt::ForegroundRole: { + if ( theValue.isValid() && theValue.canConvert( QVariant::Font ) ) + setCellForeground( theRow, theColumn, theValue.value() ); + } + break; + case Qt::BackgroundRole: { + if ( theValue.isValid() && theValue.canConvert( QVariant::Font ) ) + setCellBackground( theRow, theColumn, theValue.value() ); + } + break; + default: + break; + } +} + void QtxTable::setCellData( const int row, const int col, const QVariant& val ) { if ( !val.isValid() ) @@ -1319,7 +1435,15 @@ QTableWidgetItem* QtxTable::getItem( const int row, const int col, const bool cr return anItem; } -QModelIndexList QtxTable::getSelectedIndexes() +/*! + * Returns the table selection model + */ +QItemSelectionModel* QtxTable::selectionModel() const +{ + return QTableWidget::selectionModel(); +} + +QModelIndexList QtxTable::getSelectedIndexes() const { return selectedIndexes(); } diff --git a/src/Qtx/QtxTable.h b/src/Qtx/QtxTable.h index 283a11bd3..06efad63d 100644 --- a/src/Qtx/QtxTable.h +++ b/src/Qtx/QtxTable.h @@ -23,6 +23,7 @@ #define QTXTABLE_H #include "Qtx.h" +#include "QtxTableInterface.h" #include #include @@ -44,7 +45,7 @@ class QtxStyleWrap; #pragma warning( disable : 4251 ) #endif -class QTX_EXPORT QtxTable : public QTableWidget +class QTX_EXPORT QtxTable : public QTableWidget, public QtxTableInterface { Q_OBJECT @@ -58,6 +59,9 @@ public: QtxTable( int, int, QWidget* = 0, const char* = 0 ); virtual ~QtxTable(); + virtual int rowCount() const; + virtual int columnCount() const; + bool headerEditable( Qt::Orientation, const int = -1 ) const; bool editHeader( Qt::Orientation, const int ); @@ -79,25 +83,31 @@ public: int numHeaders( const Qt::Orientation ) const; void setNumHeaders( const Qt::Orientation, const int ); - virtual QVariant headerData( const Qt::Orientation, const int, const int = Qt::DisplayRole ) const; + virtual QVariant headerData( const int, const Qt::Orientation, + const int = Qt::DisplayRole ) const; virtual QFont headerFont( const Qt::Orientation, const int ) const; virtual QColor headerForeground( const Qt::Orientation, const int ) const; virtual QColor headerBackground( const Qt::Orientation, const int ) const; virtual QIcon headerIcon( const Qt::Orientation, const int ) const; - virtual void setHeaderData( const Qt::Orientation, const int, const QVariant&, + virtual void setHeaderData( const int, const Qt::Orientation, const QVariant&, const int = Qt::DisplayRole ); virtual void setHeaderFont( const Qt::Orientation, const int, const QFont& ); virtual void setHeaderForeground( const Qt::Orientation, const int, const QColor& ); virtual void setHeaderBackground( const Qt::Orientation, const int, const QColor& ); virtual void setHeaderIcon( const Qt::Orientation, const int, const QIcon& ); + virtual QVariant data( const int theRow, const int theColumn, + const int theRole = Qt::DisplayRole ) const; virtual QVariant cellData( const int, const int ) const; virtual QFont cellFont( const int, const int ) const; virtual QColor cellForeground( const int, const int ) const; virtual QColor cellBackground( const int, const int ) const; virtual QIcon cellIcon( const int, const int ) const; + virtual void setData( const int theRow, const int theColumn, + const QVariant& theValue, + const int theRole = Qt::DisplayRole ); virtual void setCellData( const int, const int, const QVariant& ); virtual void setCellFont( const int, const int, const QFont& ); virtual void setCellForeground( const int, const int, const QColor& ); @@ -105,7 +115,10 @@ public: virtual void setCellIcon( const int, const int, QIcon& ); virtual QTableWidgetItem* getItem( const int, const int, const bool = true ); - virtual QModelIndexList getSelectedIndexes(); + + virtual QItemSelectionModel* selectionModel() const; + virtual QModelIndexList getSelectedIndexes() const; + bool indexPosition( const QModelIndex&, int&, int& ) const; //virtual void paintCell( QPainter*, int, int, const QRect&, bool, const QColorGroup& ); diff --git a/src/Qtx/QtxTableInterface.h b/src/Qtx/QtxTableInterface.h new file mode 100644 index 000000000..0dd3765c3 --- /dev/null +++ b/src/Qtx/QtxTableInterface.h @@ -0,0 +1,119 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxTableInterface.h +// Author: Natalia Ermolaeva + +#ifndef QTXTABLEINTERFACE_H +#define QTXTABLEINTERFACE_H + +#include "Qtx.h" + +class QVariant; +class QItemSelectionModel; + +#ifdef WIN32 +#pragma warning( disable : 4251 ) +#endif + +class QTX_EXPORT QtxTableInterface +{ +public: + QtxTableInterface() {}; + virtual ~QtxTableInterface() {}; + + /*! + Returns a table row count + */ + virtual int rowCount() const = 0; + + /** + * Returns a table column count + */ + virtual int columnCount() const = 0; + + /* Returns a table header value + * @param theSection + * a header section + * @param theOrientation + * a horizontal or vertical orientation + * @param theRole + * a type of modification, that should be applyed to table + */ + virtual QVariant headerData( const int theSection, const Qt::Orientation theOrientation, + const int theRole = Qt::DisplayRole ) const = 0; + + /* Sets a table header value + * @param theSection + * a header section + * @param theOrientation + * a horizontal or vertical orientation + * @param theValue + * a value + * @param theRole + * a type of modification, that should be applyed to table + */ + virtual void setHeaderData( const int theSection, + const Qt::Orientation theOrientation, + const QVariant& theValue, + const int theRole = Qt::DisplayRole ) = 0; + + /*! + * Returns a table cell value + * @param theRow + * a row position + * @param theColumn + * a column position + * @param theRole + * a type of modification, that should be applyed to table + */ + virtual QVariant data( const int theRow, const int theColumn, + const int theRole = Qt::DisplayRole ) const = 0; + + /*! + * Set the value into a table cell + * @param theRow + * a row position + * @param theColumn + * a column position + * @param theValue + * a value + * @param theRole + * a type of modification, that should be applyed to table + */ + virtual void setData( const int theRow, const int theColumn, + const QVariant& theValue, + const int theRole = Qt::DisplayRole ) = 0; + + /*! + * Returns the table selection model + */ + virtual QItemSelectionModel* selectionModel() const = 0; + + /** + * + */ + virtual QModelIndexList getSelectedIndexes() const = 0; + +}; + +#ifdef WIN32 +#pragma warning( default: 4251 ) +#endif + +#endif // QTXTABLE_H diff --git a/src/TableViewer/TableViewer_ViewModel.cxx b/src/TableViewer/TableViewer_ViewModel.cxx index db0d1a2e0..8643f8602 100755 --- a/src/TableViewer/TableViewer_ViewModel.cxx +++ b/src/TableViewer/TableViewer_ViewModel.cxx @@ -22,7 +22,8 @@ #include "TableViewer_ViewWindow.h" #include "TableViewer_ViewManager.h" -#include +#include + /*! Constructor */ @@ -56,7 +57,7 @@ SUIT_ViewWindow* TableViewer_Viewer::createView( SUIT_Desktop* theDesktop ) void TableViewer_Viewer::initView( TableViewer_ViewWindow* theVW ) { theVW->initLayout(); - QtxTable* tbl = theVW->table(); + QtxTableInterface* tbl = theVW->table(); //if ( tbl && getViewManager() ) // tbl->viewport()->installEventFilter( getViewManager() ); } diff --git a/src/TableViewer/TableViewer_ViewWindow.cxx b/src/TableViewer/TableViewer_ViewWindow.cxx index ba9fc478f..dd9dec8b6 100755 --- a/src/TableViewer/TableViewer_ViewWindow.cxx +++ b/src/TableViewer/TableViewer_ViewWindow.cxx @@ -32,8 +32,9 @@ #include #include - #include +#include + #include #include #include @@ -50,34 +51,6 @@ TableViewer_ViewWindow::TableViewer_ViewWindow( SUIT_Desktop* theDesktop, { myModel = theModel; myToolBar = new QtxToolBar( true, tr("LBL_TOOLBAR_LABEL"), this ); - - // fill table - /* - myTable->setColumnCount(3); - myTable->setRowCount(5); - myTable->setCellBackground( 1, 1, Qt::red ); - myTable->setCellForeground( 1, 1, Qt::blue ); - QFont aFont = myTable->font(); - aFont.setItalic( true ); - myTable->setCellFont( 1, 1, aFont ); - myTable->setCellFont( 0, 0, aFont ); - - aFont.setUnderline( true ); - myTable->setCellFont( 0, 1, aFont ); - - myTable->setCellBackground( 2, 2, myTable->cellBackground( 1, 1 ) ); - myTable->setCellForeground( 2, 2, myTable->cellForeground( 1, 1 ) ); - aFont = myTable->cellFont( 1, 1 ); - myTable->setCellFont( 2, 2, aFont ); - myTable->setCellBackground( 0, 1, myTable->cellBackground( 0, 0 ) ); - - myTable->setHeaderData( Qt::Horizontal, 1, "Caption"); - myTable->setHeaderBackground( Qt::Horizontal, 1, Qt::green ); - myTable->setHeaderFont(Qt::Horizontal, 0, aFont ); - - myTable->setHeaderFont(Qt::Vertical, 4, myTable->headerFont( Qt::Horizontal, 0 ) ); - //backgroundColor( HorizontalHeader, 1, 1 ) ); - */ } /*! @@ -87,7 +60,7 @@ TableViewer_ViewWindow::~TableViewer_ViewWindow() { } -QtxTable* TableViewer_ViewWindow::table() const +QtxTableInterface* TableViewer_ViewWindow::table() const { return myTable; } @@ -99,7 +72,9 @@ QtxTable* TableViewer_ViewWindow::table() const void TableViewer_ViewWindow::initLayout() { myTable = createTable(); - setCentralWidget( myTable ); + QWidget* aWidget = dynamic_cast( myTable ); + if ( aWidget ) + setCentralWidget( aWidget ); createActions(); createToolBar(); @@ -107,7 +82,8 @@ void TableViewer_ViewWindow::initLayout() QImage TableViewer_ViewWindow::dumpView() { - return QPixmap::grabWidget( table() ).toImage(); + QWidget* aWidget = dynamic_cast( table() ); + return aWidget ? QPixmap::grabWidget( aWidget ).toImage() : QImage(); //return QPixmap::grabWindow( table()->winId() ).toImage(); } @@ -172,21 +148,8 @@ int TableViewer_ViewWindow::numCols( const ContentType type ) const QString TableViewer_ViewWindow::text( const ContentType type, const int row, const int col ) const { - QString aTxt = ""; - switch ( type ) { - case VerticalHeader: - aTxt = myTable->headerData( Qt::Vertical, row ).toString(); - break; - case HorizontalHeader: - aTxt = myTable->headerData( Qt::Horizontal, col ).toString(); - break; - case Cells: - aTxt = myTable->cellData( row, col ).toString(); - break; - default: - break; - } - return aTxt; + QVariant aValue = value( type, row, col, Qt::DisplayRole ); + return aValue.isValid() ? aValue.toString() : ""; } QString TableViewer_ViewWindow::image( const ContentType, const int, const int ) const @@ -194,21 +157,18 @@ QString TableViewer_ViewWindow::image( const ContentType, const int, const int ) return ""; } -QFont TableViewer_ViewWindow::font( const ContentType type, const int row, const int col ) const +QFont TableViewer_ViewWindow::font( const ContentType type, const int row, + const int col ) const { - QFont aFont = myTable->font(); - switch ( type ) { - case VerticalHeader: - aFont = myTable->headerFont( Qt::Vertical, row ); - break; - case HorizontalHeader: - aFont = myTable->headerFont( Qt::Horizontal, col ); - break; - case Cells: - aFont = myTable->cellFont( row, col ); - break; - default: - break; + QVariant aValue = value( type, row, col, Qt::FontRole ); + + QFont aFont; + if ( aValue.isValid() && aValue.canConvert( QVariant::Font ) ) + aFont = aValue.value(); + else { + QWidget* aWidget = dynamic_cast( myTable ); + if ( aWidget ) + aFont = aWidget->font(); } return aFont; } @@ -233,43 +193,46 @@ int TableViewer_ViewWindow::fontFlags( const ContentType type, const int row, co QColor TableViewer_ViewWindow::foregroundColor( const ContentType type, const int row, const int col ) const { + QVariant aValue = value( type, row, col, Qt::ForegroundRole ); + QColor aColor; - switch ( type ) { - case VerticalHeader: - case HorizontalHeader: { - bool aHor = type == HorizontalHeader; - aColor = myTable->headerForeground( aHor ? Qt::Horizontal : Qt::Vertical, - aHor ? col : row ); - } - break; - case Cells: - aColor = myTable->cellForeground( row, col ); - break; - default: - break; - } + if ( aValue.isValid() && aValue.canConvert( QVariant::Color ) ) + aColor = aValue.value(); + return aColor; } QColor TableViewer_ViewWindow::backgroundColor( const ContentType type, const int row, const int col ) const { + QVariant aValue = value( type, row, col, Qt::BackgroundRole ); + QColor aColor; - switch ( type ) { + if ( aValue.isValid() && aValue.canConvert( QVariant::Color ) ) + aColor = aValue.value(); + return aColor; +} + +QVariant TableViewer_ViewWindow::value( const ContentType theType, const int theRow, + const int theColumn, const int theRole ) const +{ + QVariant aValue; + switch ( theType ) { case VerticalHeader: case HorizontalHeader: { - bool aHor = type == HorizontalHeader; - aColor = myTable->headerBackground( aHor ? Qt::Horizontal : Qt::Vertical, - aHor ? col : row ); - } - break; + bool aHor = theType == HorizontalHeader; + aValue = myTable->headerData( aHor ? theColumn : theRow, + aHor ? Qt::Horizontal : Qt::Vertical, + theRole ); + } + break; case Cells: - aColor = myTable->cellBackground( row, col ); + aValue = myTable->data( theRow, theColumn, theRole ); break; default: break; } - return aColor; + return aValue; } void TableViewer_ViewWindow::createToolBar() @@ -429,10 +392,10 @@ void TableViewer_ViewWindow::copyData() continue; aCopyItem.myRow = aRow-aTopRow; aCopyItem.myCol = aCol-aLeftCol; - aCopyItem.myText = text( Cells, aRow, aCol ); - aCopyItem.myBgCol = backgroundColor( Cells, aRow, aCol ); - aCopyItem.myFgCol = foregroundColor( Cells, aRow, aCol ); - aCopyItem.myFont = font( Cells, aRow, aCol ); + aCopyItem.myText = value( Cells, aRow, aCol, Qt::DisplayRole ); + aCopyItem.myBgCol = value( Cells, aRow, aCol, Qt::BackgroundRole ); + aCopyItem.myFgCol = value( Cells, aRow, aCol, Qt::ForegroundRole ); + aCopyItem.myFont = value( Cells, aRow, aCol, Qt::FontRole ); myCopyLst.append( aCopyItem ); } } @@ -463,13 +426,13 @@ void TableViewer_ViewWindow::pasteData() aCopyItem = *aCopyIt; aCol = aCopyItem.myCol+aLeftCol; aRow = aCopyItem.myRow+aTopRow; - if ( !canPaste( aRow, aCol, aCopyItem.myText ) ) + if ( !canPaste( aRow, aCol, aCopyItem.myText.toString() ) ) continue; - myTable->setCellData( aRow, aCol, aCopyItem.myText ); - myTable->setCellBackground( aRow, aCol, aCopyItem.myBgCol ); - myTable->setCellForeground( aRow, aCol, aCopyItem.myFgCol ); - myTable->setCellFont( aRow, aCol, aCopyItem.myFont ); + myTable->setData( aRow, aCol, aCopyItem.myText, Qt::DisplayRole ); + myTable->setData( aRow, aCol, aCopyItem.myBgCol, Qt::BackgroundRole ); + myTable->setData( aRow, aCol, aCopyItem.myFgCol, Qt::ForegroundRole ); + myTable->setData( aRow, aCol, aCopyItem.myFont, Qt::FontRole ); } } @@ -504,7 +467,7 @@ bool TableViewer_ViewWindow::canPasteData() aCopyItem = *aCopyIt; aCol = aCopyItem.myCol+aLeftCol; aRow = aCopyItem.myRow+aTopRow; - aCanPaste = canPaste( aRow, aCol, aCopyItem.myText ); + aCanPaste = canPaste( aRow, aCol, aCopyItem.myText.toString() ); } return aCanPaste; } @@ -577,9 +540,9 @@ bool TableViewer_ViewWindow::canPaste( const int theRow, const int theCol, const theCol < myTable->columnCount() & theCol >= 0; } -QtxTable* TableViewer_ViewWindow::createTable() +QtxTableInterface* TableViewer_ViewWindow::createTable() { - QtxTable* aTable = new QtxTable( this ); + QtxTableInterface* aTable = new QtxTable( this ); connect( aTable->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( selectionChanged() ) ); diff --git a/src/TableViewer/TableViewer_ViewWindow.h b/src/TableViewer/TableViewer_ViewWindow.h index b5590d643..bcc6fec8c 100755 --- a/src/TableViewer/TableViewer_ViewWindow.h +++ b/src/TableViewer/TableViewer_ViewWindow.h @@ -31,9 +31,8 @@ class SUIT_Desktop; class Handle(HTMLService_HTMLTable); class QImage; class QFont; -class QtxTable; +class QtxTableInterface; class QToolBar; -class QTableWidgetItem; class QItemSelection; class TABLEVIEWER_EXPORT TableViewer_ViewWindow: public SUIT_ViewWindow @@ -44,7 +43,7 @@ public: TableViewer_ViewWindow( SUIT_Desktop* , TableViewer_Viewer* ); ~TableViewer_ViewWindow(); - QtxTable* table() const; + QtxTableInterface* table() const; QToolBar* getToolBar() { return myToolBar; } virtual void initLayout(); @@ -73,7 +72,7 @@ protected: virtual bool canCopy( const int, const int ); virtual bool canPaste( const int, const int, const QString& ); - virtual QtxTable* createTable(); + virtual QtxTableInterface* createTable(); void registerAction( const int, QtxAction* ); QtxAction* createAction( const int, const QString&, const QPixmap&, const QString&, const QString&, const int = 0, QObject* = 0 ); @@ -88,18 +87,21 @@ protected: QColor foregroundColor( const ContentType, const int, const int ) const; QColor backgroundColor( const ContentType, const int, const int ) const; + QVariant value( const ContentType theType, const int theRow, + const int theColumn, const int theRole ) const; + protected slots: virtual void selectionChanged(); void onActivated(); public: typedef struct { - QString myText; - QColor myBgCol; - QColor myFgCol; - QFont myFont; - int myRow; - int myCol; + QVariant myText; + QVariant myBgCol; + QVariant myFgCol; + QVariant myFont; + int myRow; + int myCol; } TableDataItem; protected: @@ -108,7 +110,7 @@ protected: QList myCopyLst; private: - QtxTable* myTable; + QtxTableInterface* myTable; QToolBar* myToolBar; }; -- 2.39.2