summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-07-04 17:15:14 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-07-05 21:43:13 +0200
commitf54c6938f73b94fb6f722f3ea68454fee424e62e (patch)
tree641f66bd315c54fef9c6c860125ea29716376bd8
parent14f562b109042ebde90261f93952b4c730e1427d (diff)
tdf#108873 fix merge data handling in fields
This is a regression from tdf#70346 / commit 4851cde7b98226b0f82ae2b191c290173e9b06c6 It added the whole DB row as variables to the SwCalc hash set. This works correct for conditionals when hiding sections, but not for conditionals used in fields - actually they break. Previously the field would do a fallback to query the DB again, if no variable was in the dict and the only possible variables in the dict could have been user-defined fields. This handles the added variables correctly for fields. Also fixes a bug to store the DB number values as number variables and adds the record number, as SwCalc::VarLook does. Change-Id: Ib0dbeda68234e671768ede55b2012235a3680276 Reviewed-on: https://gerrit.libreoffice.org/39509 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r--sw/inc/calc.hxx8
-rw-r--r--sw/source/core/bastyp/calc.cxx8
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx8
3 files changed, 21 insertions, 3 deletions
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index 9e7b3c817d08..c6f3380cceee 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -101,10 +101,11 @@ enum class SwCalcError
class SwSbxValue : public SbxValue
{
bool bVoid;
+ bool bDBvalue;
public:
// always default to a number. otherwise it will become a SbxEMPTY
- SwSbxValue( long n = 0 ) : bVoid(false) { PutLong( n ); }
- SwSbxValue( const double& rD ) : bVoid(false) { PutDouble( rD ); }
+ SwSbxValue( long n = 0 ) : bVoid(false), bDBvalue(false) { PutLong( n ); }
+ SwSbxValue( const double& rD ) : bVoid(false), bDBvalue(false) { PutDouble( rD ); }
bool GetBool() const;
double GetDouble() const;
@@ -112,6 +113,9 @@ public:
bool IsVoidValue() {return bVoid;}
void SetVoidValue(bool bSet) {bVoid = bSet;}
+
+ bool IsDBvalue() {return bDBvalue;}
+ void SetDBvalue(bool bSet) {bDBvalue = bSet;}
};
// Calculate HashTables for VarTable and Operations
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index ccda215a50bd..80f10a9821f0 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -495,6 +495,14 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns )
pFndExp->nValue.PutDouble( pUField->GetValue() );
}
}
+ else if ( !pFndExp->pFieldType && pFndExp->nValue.IsDBvalue() )
+ {
+ if ( pFndExp->nValue.IsString() )
+ m_aErrExpr.nValue.PutString( pFndExp->nValue.GetOUString() );
+ else if ( pFndExp->nValue.IsDouble() )
+ m_aErrExpr.nValue.PutDouble( pFndExp->nValue.GetDouble() );
+ pFndExp = &m_aErrExpr;
+ }
return pFndExp;
}
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index d6671ae5d9a7..a7bccb654ef2 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2158,6 +2158,10 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
const OUString* pColNames = aColNames.getConstArray();
OUString aString;
+ // add the "record number" variable, as SwCalc::VarLook would.
+ rCalc.VarChange( GetAppCharClass().lowercase(
+ SwFieldType::GetTypeStr(TYP_DBSETNUMBERFLD) ), GetSelectedRecordId() );
+
for( int nCol = 0; nCol < aColNames.getLength(); nCol++ )
{
// get the column type
@@ -2183,7 +2187,8 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
if( bValidValue )
{
SwSbxValue aValue;
- aValue.PutString( aString );
+ aValue.PutDouble( aNumber );
+ aValue.SetDBvalue( true );
SAL_INFO( "sw.ui", "'" << pColNames[nCol] << "': " << aNumber << " / " << aString );
rCalc.VarChange( pColNames[nCol], aValue );
}
@@ -2192,6 +2197,7 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
{
SwSbxValue aValue;
aValue.PutString( aString );
+ aValue.SetDBvalue( true );
SAL_INFO( "sw.ui", "'" << pColNames[nCol] << "': " << aString );
rCalc.VarChange( pColNames[nCol], aValue );
}