From: nds Date: Fri, 28 Sep 2007 05:34:57 +0000 (+0000) Subject: Additional methods for Copy/Paste functionality. X-Git-Tag: TG_Saint_Valentine-Day~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ea11ac159a69f63bcbc26f7171d10792863d89c;p=modules%2Fgui.git Additional methods for Copy/Paste functionality. --- diff --git a/src/Qtx/QtxTable.cxx b/src/Qtx/QtxTable.cxx index ceef59d6d..724ab727d 100644 --- a/src/Qtx/QtxTable.cxx +++ b/src/Qtx/QtxTable.cxx @@ -1236,7 +1236,7 @@ QFont QtxTable::cellFont( const int row, const int col ) const QColor QtxTable::cellForeground( const int row, const int col ) const { - QColor res; + QColor res = Qt::black; QTableWidgetItem* anItem = item( row, col ); if ( anItem && anItem->foreground().style() != Qt::NoBrush ) res = anItem->foreground().color(); @@ -1245,7 +1245,7 @@ QColor QtxTable::cellForeground( const int row, const int col ) const QColor QtxTable::cellBackground( const int row, const int col ) const { - QColor res; + QColor res = Qt::white; QTableWidgetItem* anItem = item( row, col ); if ( anItem && anItem->background().style() != Qt::NoBrush ) res = anItem->background().color(); @@ -1289,6 +1289,46 @@ void QtxTable::setCellBackground( const int row, const int col, const QColor& c anItem->setBackground( c ); } +/*! + Return item from cell + \param row - table row + \param col - table column + \param created - if item not exit and create=true, it will be created +*/ +QTableWidgetItem* QtxTable::getItem( const int row, const int col, const bool created ) +{ + QTableWidgetItem* anItem = item( row, col ); + if ( !anItem && created && row < rowCount() && col < columnCount() ) { + anItem = new QTableWidgetItem(); + setItem( row, col, anItem ); + } + return anItem; +} + +QModelIndexList QtxTable::getSelectedIndexes() +{ + return selectedIndexes(); +} + +bool QtxTable::indexPosition( const QModelIndex& theIndex, int& theRow, + int& theCol ) const +{ + theRow = -1; + theCol = -1; + QAbstractTableModel* aModel = ::qobject_cast + ( model() ); + if ( aModel ) { + for ( int i = 0, aNbCols = columnCount(); i < aNbCols; i++ ) + for ( int j = 0, aNbRows = rowCount(); j < aNbRows; j++ ) + if ( aModel->index( j, i ) == theIndex ) { + theRow = i; + theCol = j; + break; + } + } + return theRow != -1 && theCol != -1; +} + /*void QtxTable::paintCell( QPainter* p, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { @@ -1387,23 +1427,6 @@ void QtxTable::resizeEvent( QResizeEvent* e ) //updateGeometries(); } -/*! - Return item from cell - \param row - table row - \param col - table column - \param created - if item not exit and create=true, it will be created -*/ -QTableWidgetItem* QtxTable::getItem( const int row, const int col, const bool created ) -{ - QTableWidgetItem* anItem = item( row, col ); - if ( !anItem && created && row < rowCount() && col < columnCount() ) { - anItem = new QTableWidgetItem(); - setItem( row, col, anItem ); - } - return anItem; -} - - /*! Starts edition of header \param o - header orientation diff --git a/src/Qtx/QtxTable.h b/src/Qtx/QtxTable.h index 077dc9cb0..019fb9012 100644 --- a/src/Qtx/QtxTable.h +++ b/src/Qtx/QtxTable.h @@ -29,6 +29,7 @@ #include #include #include +#include //#include //#include @@ -101,7 +102,11 @@ public: void setCellFont( const int, const int, const QFont& ); void setCellForeground( const int, const int, const QColor& ); void setCellBackground( const int, const int, const QColor& ); - void setCellIcont( const int, const int, QIcon& ); + void setCellIcon( const int, const int, QIcon& ); + + virtual QTableWidgetItem* getItem( const int, const int, const bool = true ); + QModelIndexList getSelectedIndexes(); + bool indexPosition( const QModelIndex&, int&, int& ) const; //virtual void paintCell( QPainter*, int, int, const QRect&, bool, const QColorGroup& ); @@ -152,8 +157,6 @@ protected: QHeaderView* header( Qt::Orientation o ) const; virtual QRect headerSectionRect( QHeaderView*, const int, int* = 0 ) const; - QTableWidgetItem* getItem( const int, const int, const bool = true ); - private: typedef QMap HeaderState; typedef QVector HeaderVector;