summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-09-01 20:35:51 +0200
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2017-01-11 22:28:53 +0000
commitbbb2a2bac5486b9a9b9d7061f058defc11fc447f (patch)
tree4fe41f9d610b4af64c0b28885dbe8eb5c4bf04c1
parent33c1491acb3fd6b87ac16d80ed728f423762e867 (diff)
tdf#101841 MM correctly account record selections
Don't reset the pParam->xResultSet for selections when querying the result count. This actually resets the selection. * MM just increment after a successful next record This correctly counts the record id from 1, while using 0 for the first item in the selection array. (cherry picked from commit 178a23a827f16e046e5d5efb2aa2aa3fc990452a) * MM account next record fields for progress dialog When calculating the maximum document count, we were not accounting "next record" fields in the document, like in labels etc. Also any selection of records was ignored. Fixes accounting part of tdf#101841. (cherry picked from commit 260cd3aeea2d02507dd131ee2028c4f48f7562f8) Change-Id: I458e9e2e1af122f8324bcd873fd35ffcf89d62d3 Reviewed-on: https://gerrit.libreoffice.org/32184 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r--sw/inc/IDocumentFieldsAccess.hxx2
-rw-r--r--sw/source/core/doc/DocumentFieldsManager.cxx33
-rw-r--r--sw/source/core/inc/DocumentFieldsManager.hxx1
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx45
4 files changed, 68 insertions, 13 deletions
diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx
index f9b116b716c2..6280e9a34b09 100644
--- a/sw/inc/IDocumentFieldsAccess.hxx
+++ b/sw/inc/IDocumentFieldsAccess.hxx
@@ -130,6 +130,8 @@ namespace com { namespace sun { namespace star { namespace uno { class Any; } }
virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField& rField) = 0;
+ virtual sal_Int32 GetRecordsPerDocument() const = 0;
+
protected:
virtual ~IDocumentFieldsAccess() {};
};
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index 8c638666e873..f99ad757320b 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -913,7 +913,6 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp
SwSection* pSect = const_cast<SwSection*>((*it)->GetSection());
if( pSect )
{
-
SwSbxValue aValue = aCalc.Calculate(
pSect->GetCondition() );
if(!aValue.IsVoidValue())
@@ -1186,6 +1185,38 @@ void DocumentFieldsManager::UpdateUsrFields()
}
}
+sal_Int32 DocumentFieldsManager::GetRecordsPerDocument() const
+{
+ sal_Int32 nRecords = 1;
+
+ mpUpdateFields->MakeFieldList( m_rDoc, true, GETFLD_ALL );
+ if( mpUpdateFields->GetSortLst()->empty() )
+ return nRecords;
+
+ for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin();
+ it != mpUpdateFields->GetSortLst()->end(); ++it )
+ {
+ const SwTextField *pTextField = (*it)->GetTextField();
+ if( !pTextField )
+ continue;
+
+ const SwFormatField &pFormatField = pTextField->GetFormatField();
+ const SwField* pField = pFormatField.GetField();
+
+ switch( pField->GetTyp()->Which() )
+ {
+ case RES_DBNEXTSETFLD:
+ case RES_DBNUMSETFLD:
+ nRecords++;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return nRecords;
+}
+
void DocumentFieldsManager::UpdatePageFields( SfxPoolItem* pMsgHint )
{
for( SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i )
diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx b/sw/source/core/inc/DocumentFieldsManager.hxx
index a5facc69392d..fc6f9afc9266 100644
--- a/sw/source/core/inc/DocumentFieldsManager.hxx
+++ b/sw/source/core/inc/DocumentFieldsManager.hxx
@@ -60,6 +60,7 @@ public:
virtual bool IsNewFieldLst() const override;
virtual void SetNewFieldLst( bool bFlag) override;
virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField& rField) override;
+ virtual sal_Int32 GetRecordsPerDocument() const override;
//Non Interface methods
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index fe9e87f727bb..c5b512337b44 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -177,10 +177,14 @@ static SfxObjectShell* lcl_CreateWorkingDocument(
SwDBManager** const pDBManager,
SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc );
-static bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<sdbc::XResultSet>& xResultSet )
+static bool lcl_getCountFromResultSet( sal_Int32& rCount, const SwDSParam* pParam )
{
- uno::Reference<beans::XPropertySet> xPrSet(xResultSet, uno::UNO_QUERY);
- if(xPrSet.is())
+ rCount = pParam->aSelection.getLength();
+ if ( rCount > 0 )
+ return true;
+
+ uno::Reference<beans::XPropertySet> xPrSet(pParam->xResultSet, uno::UNO_QUERY);
+ if ( xPrSet.is() )
{
try
{
@@ -189,8 +193,8 @@ static bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<s
aFinal >>= bFinal;
if(!bFinal)
{
- xResultSet->last();
- xResultSet->first();
+ pParam->xResultSet->last();
+ pParam->xResultSet->first();
}
uno::Any aCount = xPrSet->getPropertyValue("RowCount");
if( aCount >>= rCount )
@@ -1265,16 +1269,33 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
}
sal_Int32 nDocNo = 1;
- sal_Int32 nDocCount = 0;
+
// For single file mode, the number of pages in the target document so far, which is used
// by AppendDoc() to adjust position of page-bound objects. Getting this information directly
// from the target doc would require repeated layouts of the doc, which is expensive, but
// it can be manually computed from the source documents (for which we do layouts, so the page
// count is known, and there is a blank page between each of them in the target document).
int targetDocPageCount = 0;
- if( !bIsMergeSilent && !bMT_PRINTER &&
- lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) )
- static_cast<CreateMonitor*>( pProgressDlg.get() )->SetTotalCount( nDocCount );
+
+ if( !bIsMergeSilent && !bMT_PRINTER )
+ {
+ sal_Int32 nRecordCount = 1;
+ lcl_getCountFromResultSet( nRecordCount, pImpl->pMergeData );
+
+ // syncronized docs don't auto-advance the record set, but there is a
+ // "security" check, which will always advance the record set, if there
+ // is no "next record" field in a synchronized doc => nRecordPerDoc > 0
+ sal_Int32 nRecordPerDoc = pSourceShell->GetDoc()
+ ->getIDocumentFieldsAccess().GetRecordsPerDocument();
+ if ( bSynchronizedDoc && (nRecordPerDoc > 1) )
+ --nRecordPerDoc;
+ assert( nRecordPerDoc > 0 );
+
+ sal_Int32 nMaxDocs = nRecordCount / nRecordPerDoc;
+ if ( 0 != nRecordCount % nRecordPerDoc )
+ nMaxDocs += 1;
+ static_cast<CreateMonitor*>( pProgressDlg.get() )->SetTotalCount( nMaxDocs );
+ }
long nStartRow, nEndRow;
bool bFreezedLayouts = false;
@@ -2173,7 +2194,7 @@ static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action )
else
{
sal_Int32 nPos = 0;
- pParam->aSelection.getConstArray()[ pParam->nSelectionIndex++ ] >>= nPos;
+ pParam->aSelection.getConstArray()[ pParam->nSelectionIndex ] >>= nPos;
pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos );
}
}
@@ -2188,11 +2209,11 @@ static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action )
if( !pParam->bEndOfDB && nBefore == pParam->xResultSet->getRow() )
{
// next returned true but it didn't move
- pParam->bEndOfDB = true;
+ ::dbtools::throwFunctionSequenceException( pParam->xResultSet );
}
- ++pParam->nSelectionIndex;
}
+ ++pParam->nSelectionIndex;
bRet = !pParam->bEndOfDB;
}
catch( const uno::Exception &e )