From b6bacd22bb4e4105c3239972299d2b63f1f30c54 Mon Sep 17 00:00:00 2001 From: ptv Date: Thu, 5 Oct 2006 12:07:22 +0000 Subject: [PATCH] add removeSelected - to remove selected rows or columns --- src/Qtx/QtxTable.cxx | 37 +++++++++++++++++++++++++++++++++++++ src/Qtx/QtxTable.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/src/Qtx/QtxTable.cxx b/src/Qtx/QtxTable.cxx index 6d110e63f..9d4cc49c2 100644 --- a/src/Qtx/QtxTable.cxx +++ b/src/Qtx/QtxTable.cxx @@ -24,6 +24,7 @@ #ifndef QT_NO_TABLE #include +#include /*! Constructor @@ -475,4 +476,40 @@ void QtxTable::updateHeaderEditor() myHeaderEditor->move( r.topLeft() ); } +/*! + Remove selected rows or columns if any of cell selected in it +*/ +void QtxTable::removeSelected( const bool row ) +{ + QValueList idsList; + QMap idMap; + int i = 0; + for ( int nb = numSelections(); i < nb; i++ ) + { + QTableSelection sel = selection( i ); + int minId = row ? sel.topRow() : sel.leftCol(); + int maxId = row ? sel.bottomRow() : sel.rightCol(); + for ( ; minId <= maxId; minId++ ) + if ( !idMap.contains( minId ) ) + { + idMap[ minId ] = 1; + idsList.append( minId ); + } + } + if ( idMap.isEmpty() ) + return; + + qHeapSort( idsList ); + QMemArray idsArr( idsList.count() ); + QValueList::const_iterator it = idsList.begin(); + QValueList::const_iterator itEnd = idsList.end(); + for ( i = 0; it != itEnd; ++it, ++i ) + idsArr[ i ] = *it; + + if ( row ) + removeRows ( idsArr ); + else + removeColumns ( idsArr ); +} + #endif diff --git a/src/Qtx/QtxTable.h b/src/Qtx/QtxTable.h index a7d4f3ebf..dd38208c7 100644 --- a/src/Qtx/QtxTable.h +++ b/src/Qtx/QtxTable.h @@ -46,6 +46,8 @@ public: bool editHeader( Orientation, const int ); void endEditHeader( const bool = true ); + void removeSelected( const bool row = true ); + virtual bool eventFilter( QObject*, QEvent* ); virtual void setNumRows( int ); -- 2.39.2