Kaydet (Commit) c55d0504 authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

fdo#46163 convert bound values to bound column's type

üst fc593ac6
...@@ -326,7 +326,7 @@ namespace frm ...@@ -326,7 +326,7 @@ namespace frm
// propagate // propagate
if ( m_eListSourceType == ListSourceType_VALUELIST ) if ( m_eListSourceType == ListSourceType_VALUELIST )
{ {
m_aBoundValues = m_aListSourceValues; setBoundValues(m_aListSourceValues);
} }
else else
{ {
...@@ -556,7 +556,7 @@ namespace frm ...@@ -556,7 +556,7 @@ namespace frm
OSL_FAIL("OListBoxModel::read : invalid (means unknown) version !"); OSL_FAIL("OListBoxModel::read : invalid (means unknown) version !");
ValueList().swap(m_aListSourceValues); ValueList().swap(m_aListSourceValues);
m_aBoundColumn <<= (sal_Int16)0; m_aBoundColumn <<= (sal_Int16)0;
ValueList().swap(m_aBoundValues); clearBoundValues();
m_eListSourceType = ListSourceType_VALUELIST; m_eListSourceType = ListSourceType_VALUELIST;
m_aDefaultSelectSeq.realloc(0); m_aDefaultSelectSeq.realloc(0);
defaultCommonProperties(); defaultCommonProperties();
...@@ -674,7 +674,7 @@ namespace frm ...@@ -674,7 +674,7 @@ namespace frm
// outta here if we don't have all pre-requisites // outta here if we don't have all pre-requisites
if ( !xConnection.is() || sListSource.isEmpty() ) if ( !xConnection.is() || sListSource.isEmpty() )
{ {
ValueList().swap(m_aBoundValues); clearBoundValues();
return; return;
} }
...@@ -924,7 +924,7 @@ namespace frm ...@@ -924,7 +924,7 @@ namespace frm
m_nNULLPos = 0; m_nNULLPos = 0;
} }
m_aBoundValues = aValueList; setBoundValues(aValueList);
setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( lcl_convertToStringSequence( aDisplayList ) ) ); setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( lcl_convertToStringSequence( aDisplayList ) ) );
} }
...@@ -948,7 +948,7 @@ namespace frm ...@@ -948,7 +948,7 @@ namespace frm
{ {
if ( m_eListSourceType != ListSourceType_VALUELIST ) if ( m_eListSourceType != ListSourceType_VALUELIST )
{ {
ValueList().swap(m_aBoundValues); clearBoundValues();
m_nNULLPos = -1; m_nNULLPos = -1;
m_nBoundColumnType = DataType::SQLNULL; m_nBoundColumnType = DataType::SQLNULL;
...@@ -959,20 +959,64 @@ namespace frm ...@@ -959,20 +959,64 @@ namespace frm
} }
} }
//------------------------------------------------------------------------------
void OListBoxModel::setBoundValues(const ValueList &l)
{
m_aConvertedBoundValues.clear();
m_aBoundValues = l;
}
//------------------------------------------------------------------------------
void OListBoxModel::clearBoundValues()
{
ValueList().swap(m_aConvertedBoundValues);
ValueList().swap(m_aBoundValues);
}
//------------------------------------------------------------------------------
void OListBoxModel::convertBoundValues(const sal_Int32 nFieldType) const
{
m_aConvertedBoundValues.resize(m_aBoundValues.size());
ValueList::const_iterator src = m_aBoundValues.begin();
const ValueList::const_iterator end = m_aBoundValues.end();
ValueList::iterator dst = m_aConvertedBoundValues.begin();
for (; src != end; ++src, ++dst )
{
*dst = *src;
dst->setTypeKind(nFieldType);
}
m_nConvertedBoundValuesType = nFieldType;
OSL_ENSURE(dst == m_aConvertedBoundValues.end(), "OListBoxModel::convertBoundValues expected to have overwritten all of m_aConvertedBoundValues, but did not.");
}
//------------------------------------------------------------------------------
sal_Int32 OListBoxModel::getValueType() const
{
return impl_hasBoundComponent() ? m_nBoundColumnType : getFieldType();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ValueList OListBoxModel::impl_getValues() const ValueList OListBoxModel::impl_getValues() const
{ {
const sal_Int32 nFieldType = getValueType();
if ( !m_aConvertedBoundValues.empty() && m_nConvertedBoundValuesType == nFieldType )
return m_aConvertedBoundValues;
if ( !m_aBoundValues.empty() ) if ( !m_aBoundValues.empty() )
return m_aBoundValues; {
convertBoundValues(nFieldType);
return m_aConvertedBoundValues;
}
Sequence< ::rtl::OUString > aStringItems( getStringItemList() ); Sequence< ::rtl::OUString > aStringItems( getStringItemList() );
ValueList aValues( aStringItems.getLength() ); ValueList aValues( aStringItems.getLength() );
::std::copy( ValueList::iterator dst = aValues.begin();
aStringItems.getConstArray(), const ::rtl::OUString *src (aStringItems.getConstArray());
aStringItems.getConstArray() + aStringItems.getLength(), const ::rtl::OUString * const end = src + aStringItems.getLength();
aValues.begin() for (; src < end; ++src, ++dst )
); {
*dst = *src;
dst->setTypeKind(nFieldType);
}
return aValues; return aValues;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -1045,7 +1089,7 @@ namespace frm ...@@ -1045,7 +1089,7 @@ namespace frm
Sequence< sal_Int16 > aSelectionIndicies; Sequence< sal_Int16 > aSelectionIndicies;
ORowSetValue aCurrentValue; ORowSetValue aCurrentValue;
aCurrentValue.fill( impl_hasBoundComponent() ? m_nBoundColumnType : getFieldType(), m_xColumn ); aCurrentValue.fill( getValueType(), m_xColumn );
// reset selection for NULL values // reset selection for NULL values
if ( aCurrentValue.isNull() ) if ( aCurrentValue.isNull() )
......
...@@ -79,7 +79,9 @@ class OListBoxModel :public OBoundControlModel ...@@ -79,7 +79,9 @@ class OListBoxModel :public OBoundControlModel
::com::sun::star::form::ListSourceType m_eListSourceType; // type der list source ::com::sun::star::form::ListSourceType m_eListSourceType; // type der list source
::com::sun::star::uno::Any m_aBoundColumn; ::com::sun::star::uno::Any m_aBoundColumn;
ValueList m_aListSourceValues; ValueList m_aListSourceValues;
ValueList m_aBoundValues; ValueList m_aBoundValues; // do not write directly; use setBoundValues()
mutable ValueList m_aConvertedBoundValues;
mutable sal_Int32 m_nConvertedBoundValuesType;
::com::sun::star::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected ::com::sun::star::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected
// </properties> // </properties>
...@@ -181,8 +183,15 @@ private: ...@@ -181,8 +183,15 @@ private:
*/ */
void impl_refreshDbEntryList( bool _bForce ); void impl_refreshDbEntryList( bool _bForce );
void setBoundValues(const ValueList&);
void clearBoundValues();
ValueList impl_getValues() const; ValueList impl_getValues() const;
sal_Int32 getValueType() const;
void convertBoundValues(sal_Int32 nType) const;
bool impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; } bool impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment