summaryrefslogtreecommitdiff
path: root/toolkit/source
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-09-03 14:45:20 -0500
committerMiklos Vajna <vmiklos@suse.cz>2012-09-14 07:42:02 +0000
commit4971468b6ce2923a8803f7d79548866de48ab36e (patch)
tree39bfdde0c7b1f109c2ed8cfed0cf699096215675 /toolkit/source
parentfe08068cf9ba35105955244b8d9cd9e64e3ebb88 (diff)
gridfixes: #i117398# XMutableGridDataModel:
allow inserting rows at arbitrary positions Change-Id: Ia5af125035979951c61d6c8cd9a916e8f81bb6c0 Reviewed-on: https://gerrit.libreoffice.org/545 Reviewed-by: Miklos Vajna <vmiklos@suse.cz> Tested-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'toolkit/source')
-rw-r--r--toolkit/source/controls/grid/defaultgriddatamodel.cxx73
-rw-r--r--toolkit/source/controls/grid/defaultgriddatamodel.hxx6
-rw-r--r--toolkit/source/controls/grid/sortablegriddatamodel.cxx28
-rw-r--r--toolkit/source/controls/grid/sortablegriddatamodel.hxx2
4 files changed, 79 insertions, 30 deletions
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
index 653f0568159c..77a65627a555 100644
--- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx
+++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
@@ -101,7 +101,7 @@ namespace toolkit
::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException)
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- return m_aData.size();
+ return impl_getRowCount_nolck();
}
//------------------------------------------------------------------------------------------------------------------
@@ -189,52 +189,70 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
+ void DefaultGridDataModel::impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount )
+ {
+ OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ),
+ "DefaultGridDataModel::impl_insertRow: invalid column count!" );
+
+ // insert heading
+ m_aRowHeaders.insert( m_aRowHeaders.begin() + i_position, i_heading );
+
+ // create new data row
+ RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() );
+ RowData::iterator cellData = newRow.begin();
+ for ( const Any* pData = stl_begin( i_rowData ); pData != stl_end( i_rowData ); ++pData, ++cellData )
+ cellData->first = *pData;
+
+ // insert data row
+ m_aData.insert( m_aData.begin() + i_position, newRow );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL DefaultGridDataModel::addRow( const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException)
{
- ::comphelper::ComponentGuard aGuard( *this, rBHelper );
+ insertRow( getRowCount(), i_heading, i_data );
+ }
- sal_Int32 const columnCount = i_data.getLength();
+ //------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL DefaultGridDataModel::addRows( const Sequence< Any >& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException)
+ {
+ insertRows( getRowCount(), i_headings, i_data );
+ }
- // store header name
- m_aRowHeaders.push_back( i_heading );
+ //------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL DefaultGridDataModel::insertRow( ::sal_Int32 i_index, const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, IndexOutOfBoundsException)
+ {
+ ::comphelper::ComponentGuard aGuard( *this, rBHelper );
- // store row m_aData
- impl_addRow( i_data );
+ if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+
+ // actually insert the row
+ impl_insertRow( i_index, i_heading, i_data );
// update column count
+ sal_Int32 const columnCount = i_data.getLength();
if ( columnCount > m_nColumnCount )
m_nColumnCount = columnCount;
- sal_Int32 const rowIndex = sal_Int32( m_aData.size() - 1 );
broadcast(
- GridDataEvent( *this, -1, -1, rowIndex, rowIndex ),
+ GridDataEvent( *this, -1, -1, i_index, i_index ),
&XGridDataListener::rowsInserted,
aGuard
);
}
//------------------------------------------------------------------------------------------------------------------
- void DefaultGridDataModel::impl_addRow( Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount )
- {
- OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ),
- "DefaultGridDataModel::impl_addRow: invalid column count!" );
-
- RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() );
- RowData::iterator cellData = newRow.begin();
- for ( const Any* pData = stl_begin( i_rowData ); pData != stl_end( i_rowData ); ++pData, ++cellData )
- cellData->first = *pData;
-
- m_aData.push_back( newRow );
- }
-
- //------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::addRows( const Sequence< Any >& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException)
+ void SAL_CALL DefaultGridDataModel::insertRows( ::sal_Int32 i_index, const Sequence< Any>& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException)
{
if ( i_headings.getLength() != i_data.getLength() )
throw IllegalArgumentException( ::rtl::OUString(), *this, -1 );
::comphelper::ComponentGuard aGuard( *this, rBHelper );
+ if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+
sal_Int32 const rowCount = i_headings.getLength();
if ( rowCount == 0 )
return;
@@ -250,17 +268,14 @@ namespace toolkit
for ( sal_Int32 row=0; row<rowCount; ++row )
{
- m_aRowHeaders.push_back( i_headings[row] );
- impl_addRow( i_data[row], maxColCount );
+ impl_insertRow( i_index + row, i_headings[row], i_data[row], maxColCount );
}
if ( maxColCount > m_nColumnCount )
m_nColumnCount = maxColCount;
- sal_Int32 const firstRow = sal_Int32( m_aData.size() - rowCount );
- sal_Int32 const lastRow = sal_Int32( m_aData.size() - 1 );
broadcast(
- GridDataEvent( *this, -1, -1, firstRow, lastRow ),
+ GridDataEvent( *this, -1, -1, i_index, i_index + rowCount - 1 ),
&XGridDataListener::rowsInserted,
aGuard
);
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.hxx b/toolkit/source/controls/grid/defaultgriddatamodel.hxx
index c9c398ede17b..9d873f75016e 100644
--- a/toolkit/source/controls/grid/defaultgriddatamodel.hxx
+++ b/toolkit/source/controls/grid/defaultgriddatamodel.hxx
@@ -66,6 +66,8 @@ public:
// XMutableGridDataModel
virtual void SAL_CALL addRow( const Any& i_heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL addRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL insertRow( ::sal_Int32 i_index, const ::com::sun::star::uno::Any& i_heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException);
+ virtual void SAL_CALL insertRows( ::sal_Int32 i_index, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL updateCellData( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
@@ -106,7 +108,9 @@ private:
::comphelper::ComponentGuard & i_instanceLock
);
- void impl_addRow( Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 );
+ void impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 );
+
+ ::sal_Int32 impl_getRowCount_nolck() const { return sal_Int32( m_aData.size() ); }
CellData const & impl_getCellData_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex ) const;
CellData& impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex );
diff --git a/toolkit/source/controls/grid/sortablegriddatamodel.cxx b/toolkit/source/controls/grid/sortablegriddatamodel.cxx
index e71d218caca0..d64e68fdbcb0 100644
--- a/toolkit/source/controls/grid/sortablegriddatamodel.cxx
+++ b/toolkit/source/controls/grid/sortablegriddatamodel.cxx
@@ -605,6 +605,34 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL SortableGridDataModel::insertRow( ::sal_Int32 i_index, const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, IndexOutOfBoundsException)
+ {
+ MethodGuard aGuard( *this, rBHelper );
+ DBG_CHECK_ME();
+
+ ::sal_Int32 const rowIndex = i_index == getRowCount() ? i_index : impl_getPrivateRowIndex_throw( i_index );
+ // note that |RowCount| is a valid index in this method, but not for impl_getPrivateRowIndex_throw
+
+ Reference< XMutableGridDataModel > const delegator( m_delegator );
+ aGuard.clear();
+ delegator->insertRow( i_index, i_heading, i_data );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL SortableGridDataModel::insertRows( ::sal_Int32 i_index, const Sequence< Any>& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException)
+ {
+ MethodGuard aGuard( *this, rBHelper );
+ DBG_CHECK_ME();
+
+ ::sal_Int32 const rowIndex = i_index == getRowCount() ? i_index : impl_getPrivateRowIndex_throw( i_index );
+ // note that |RowCount| is a valid index in this method, but not for impl_getPrivateRowIndex_throw
+
+ Reference< XMutableGridDataModel > const delegator( m_delegator );
+ aGuard.clear();
+ delegator->insertRows( i_index, i_headings, i_data );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL SortableGridDataModel::removeRow( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException)
{
MethodGuard aGuard( *this, rBHelper );
diff --git a/toolkit/source/controls/grid/sortablegriddatamodel.hxx b/toolkit/source/controls/grid/sortablegriddatamodel.hxx
index c31aff72a300..53f95a973468 100644
--- a/toolkit/source/controls/grid/sortablegriddatamodel.hxx
+++ b/toolkit/source/controls/grid/sortablegriddatamodel.hxx
@@ -84,6 +84,8 @@ namespace toolkit
// XMutableGridDataModel
virtual void SAL_CALL addRow( const ::com::sun::star::uno::Any& Heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL addRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL insertRow( ::sal_Int32 i_index, const ::com::sun::star::uno::Any& i_heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException);
+ virtual void SAL_CALL insertRows( ::sal_Int32 i_index, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL updateCellData( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);