Kaydet (Commit) ccb8b830 authored tarafından Noel Grandin's avatar Noel Grandin

convert FilterComponent to scoped enum

and simplify the overly-general logic in FilterManager

Change-Id: I2cbd9db6a53894cd13713a5cc0d1807cec456848
üst bf7690bc
......@@ -39,8 +39,7 @@ namespace dbtools
using namespace connectivity;
FilterManager::FilterManager( )
:m_aFilterComponents( FC_COMPONENT_COUNT )
,m_bApplyPublicFilter( true )
:m_bApplyPublicFilter( true )
{
}
......@@ -63,16 +62,19 @@ namespace dbtools
const OUString& FilterManager::getFilterComponent( FilterComponent _eWhich ) const
{
return m_aFilterComponents[ _eWhich ];
return _eWhich == FilterComponent::PublicFilter ? m_aPublicFilterComponent : m_aLinkFilterComponent;
}
void FilterManager::setFilterComponent( FilterComponent _eWhich, const OUString& _rComponent )
{
m_aFilterComponents[ _eWhich ] = _rComponent;
if (_eWhich == FilterComponent::PublicFilter)
m_aPublicFilterComponent = _rComponent;
else
m_aLinkFilterComponent = _rComponent;
try
{
if ( m_xComponentAggregate.is() && (( _eWhich != fcPublicFilter ) || m_bApplyPublicFilter ) )
if ( m_xComponentAggregate.is() && (( _eWhich != FilterComponent::PublicFilter ) || m_bApplyPublicFilter ) )
m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), makeAny( getComposedFilter() ) );
}
catch( const Exception& )
......@@ -91,7 +93,7 @@ namespace dbtools
try
{
if ( m_xComponentAggregate.is() && !getFilterComponent( fcPublicFilter ).isEmpty() )
if ( m_xComponentAggregate.is() && !getFilterComponent( FilterComponent::PublicFilter ).isEmpty() )
{ // only if there changed something
m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), makeAny( getComposedFilter() ) );
}
......@@ -120,32 +122,25 @@ namespace dbtools
bool FilterManager::isThereAtMostOneComponent( OUStringBuffer& o_singleComponent ) const
{
sal_Int32 nOnlyNonEmpty = -1;
sal_Int32 i;
for ( i = getFirstApplicableFilterIndex(); i < FC_COMPONENT_COUNT; ++i )
{
if ( !m_aFilterComponents[ i ].isEmpty() )
{
if ( nOnlyNonEmpty != -1 )
// it's the second non-empty component
break;
else
nOnlyNonEmpty = i;
}
}
if ( nOnlyNonEmpty == -1 )
{
o_singleComponent.makeStringAndClear();
if (m_bApplyPublicFilter) {
if (!m_aPublicFilterComponent.isEmpty() && !m_aLinkFilterComponent.isEmpty())
return false;
if (!m_aPublicFilterComponent.isEmpty())
o_singleComponent = m_aPublicFilterComponent;
else if (!m_aLinkFilterComponent.isEmpty())
o_singleComponent = m_aLinkFilterComponent;
else
o_singleComponent.makeStringAndClear();
return true;
}
if ( i == FC_COMPONENT_COUNT )
else
{
// we found only one non-empty filter component
o_singleComponent = m_aFilterComponents[ nOnlyNonEmpty ];
if (m_aLinkFilterComponent.isEmpty())
o_singleComponent.makeStringAndClear();
else
o_singleComponent = m_aLinkFilterComponent;
return true;
}
return false;
}
......@@ -157,8 +152,9 @@ namespace dbtools
if ( !isThereAtMostOneComponent( aComposedFilter ) )
{
// append the single components
for ( sal_Int32 i = getFirstApplicableFilterIndex(); i < FC_COMPONENT_COUNT; ++i )
appendFilterComponent( aComposedFilter, m_aFilterComponents[ i ] );
if (m_bApplyPublicFilter)
appendFilterComponent( aComposedFilter, m_aPublicFilterComponent );
appendFilterComponent( aComposedFilter, m_aLinkFilterComponent );
}
return aComposedFilter.makeStringAndClear();
......
......@@ -398,7 +398,7 @@ namespace dbtools
}
// now set this filter at the 's filter manager
_rFilterManager.setFilterComponent( FilterManager::fcLinkFilter, sAdditionalFilter.makeStringAndClear() );
_rFilterManager.setFilterComponent( FilterManager::FilterComponent::LinkFilter, sAdditionalFilter.makeStringAndClear() );
_rColumnsInLinkDetails = true;
}
......
......@@ -496,14 +496,14 @@ void SAL_CALL DatabaseDataProvider::setCommandType(::sal_Int32 the_value) throw
OUString SAL_CALL DatabaseDataProvider::getFilter() throw (uno::RuntimeException, std::exception)
{
osl::MutexGuard g(m_aMutex);
return m_aFilterManager.getFilterComponent( dbtools::FilterManager::fcPublicFilter );
return m_aFilterManager.getFilterComponent( dbtools::FilterManager::FilterComponent::PublicFilter );
}
void SAL_CALL DatabaseDataProvider::setFilter(const OUString & the_value) throw (uno::RuntimeException, std::exception)
{
{
osl::MutexGuard g(m_aMutex);
m_aFilterManager.setFilterComponent( dbtools::FilterManager::fcPublicFilter, the_value );
m_aFilterManager.setFilterComponent( dbtools::FilterManager::FilterComponent::PublicFilter, the_value );
}
set(PROPERTY_FILTER,the_value,m_Filter);
}
......
......@@ -1500,7 +1500,7 @@ void ODatabaseForm::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
break;
case PROPERTY_ID_FILTER:
rValue <<= m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter );
rValue <<= m_aFilterManager.getFilterComponent( FilterManager::FilterComponent::PublicFilter );
break;
case PROPERTY_ID_APPLYFILTER:
......@@ -1583,7 +1583,7 @@ sal_Bool ODatabaseForm::convertFastPropertyValue( Any& rConvertedValue, Any& rOl
break;
case PROPERTY_ID_FILTER:
bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ) );
bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.getFilterComponent( FilterManager::FilterComponent::PublicFilter ) );
break;
case PROPERTY_ID_APPLYFILTER:
......@@ -1672,7 +1672,7 @@ void ODatabaseForm::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const A
{
OUString sNewFilter;
rValue >>= sNewFilter;
m_aFilterManager.setFilterComponent( FilterManager::fcPublicFilter, sNewFilter );
m_aFilterManager.setFilterComponent( FilterManager::FilterComponent::PublicFilter, sNewFilter );
}
break;
......@@ -1815,7 +1815,7 @@ PropertyState ODatabaseForm::getPropertyStateByHandle(sal_Int32 nHandle)
break;
case PROPERTY_ID_FILTER:
if ( m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ).isEmpty() )
if ( m_aFilterManager.getFilterComponent( FilterManager::FilterComponent::PublicFilter ).isEmpty() )
eState = PropertyState_DEFAULT_VALUE;
else
eState = PropertyState_DIRECT_VALUE;
......
......@@ -58,20 +58,18 @@ namespace dbtools
class OOO_DLLPUBLIC_DBTOOLS FilterManager
{
public:
enum FilterComponent
enum class FilterComponent
{
fcPublicFilter = 0, // the filter which is to be published as "Filter" property of the database component
fcLinkFilter, // the filter part which is implicitly created for a database component when connecting
// master and detail database components via column names
FC_COMPONENT_COUNT // boundary delimiter, not to be used from outside
PublicFilter, // The filter which is to be published as "Filter" property of the database component.
LinkFilter // The filter part which is implicitly created for a database component when connecting
// master and detail database components via column names.
};
private:
css::uno::Reference< css::beans::XPropertySet >
m_xComponentAggregate;
::std::vector< OUString > m_aFilterComponents;
bool m_bApplyPublicFilter;
css::uno::Reference< css::beans::XPropertySet > m_xComponentAggregate;
OUString m_aPublicFilterComponent;
OUString m_aLinkFilterComponent;
bool m_bApplyPublicFilter;
public:
/// ctor
......@@ -84,7 +82,7 @@ namespace dbtools
void dispose( );
const OUString& getFilterComponent( FilterComponent _eWhich ) const;
void setFilterComponent( FilterComponent _eWhich, const OUString& _rComponent );
void setFilterComponent( FilterComponent _eWhich, const OUString& _rComponent );
inline bool isApplyPublicFilter( ) const { return m_bApplyPublicFilter; }
void setApplyPublicFilter( bool _bApply );
......@@ -100,12 +98,6 @@ namespace dbtools
/// checks whether there is only one (or even no) non-empty filter component
bool isThereAtMostOneComponent( OUStringBuffer& o_singleComponent ) const;
/// returns the index of the first filter component which should be considered when building the composed filter
inline sal_Int32 getFirstApplicableFilterIndex() const
{
return m_bApplyPublicFilter ? fcPublicFilter : fcPublicFilter + 1;
}
};
......
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