[Libreoffice-commits] core.git: include/svl svl/qa svl/source
Tobias Lippert
drtl at fastmail.fm
Wed Jul 23 04:08:26 PDT 2014
include/svl/IndexedStyleSheets.hxx | 10 ++++
svl/qa/unit/items/test_IndexedStyleSheets.cxx | 27 ++++++++++++-
svl/source/items/IndexedStyleSheets.cxx | 54 +++++++++++++++++++++++---
svl/source/items/style.cxx | 31 ++++++++++++++
4 files changed, 113 insertions(+), 9 deletions(-)
New commits:
commit 8f8ee6fd2c50572c44363a6d5d23bd9d192fe08d
Author: Tobias Lippert <drtl at fastmail.fm>
Date: Thu Jun 26 19:59:15 2014 +0200
fdo#76754 Add Positions by StyleSheetFamily to IndexedStyleSheets
Change-Id: I4eade2d00d145d8f65ccd70a1c6bbd0a134a1ad5
Reviewed-on: https://gerrit.libreoffice.org/10346
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx
index 350628f..bc5dea7 100644
--- a/include/svl/IndexedStyleSheets.hxx
+++ b/include/svl/IndexedStyleSheets.hxx
@@ -12,6 +12,7 @@
#include <sal/types.h>
+#include <rsc/rscsfx.hxx>
#include <rtl/ustring.hxx>
#include <rtl/ref.hxx>
@@ -156,10 +157,15 @@ public:
GetNthStyleSheetThatMatchesPredicate(unsigned n, StyleSheetPredicate& predicate,
unsigned startAt = 0);
+ /** Get the positions of the style sheets which belong to a certain family.
+ */
+ const std::vector<unsigned>&
+ GetStyleSheetPositionsByFamily(SfxStyleFamily) const;
+
private:
/** Register the position of a styleName in the index */
void
- Register(const rtl::OUString& styleName, unsigned pos);
+ Register(const SfxStyleSheetBase& style, unsigned pos);
typedef std::vector<rtl::Reference<SfxStyleSheetBase> > VectorType;
/** Vector with the stylesheets to allow for index-based access.
@@ -174,6 +180,8 @@ private:
/** A map which stores the positions of style sheets by their name */
MapType mPositionsByName;
+
+ std::vector<std::vector<unsigned> > mStyleSheetPositionsByFamily;
};
} /* namespace svl */
diff --git a/svl/qa/unit/items/test_IndexedStyleSheets.cxx b/svl/qa/unit/items/test_IndexedStyleSheets.cxx
index 3b0a0e0..99b816f 100644
--- a/svl/qa/unit/items/test_IndexedStyleSheets.cxx
+++ b/svl/qa/unit/items/test_IndexedStyleSheets.cxx
@@ -21,8 +21,8 @@ using namespace svl;
class MockedStyleSheet : public SfxStyleSheetBase
{
public:
- MockedStyleSheet(const rtl::OUString& name)
- : SfxStyleSheetBase(name, NULL, SFX_STYLE_FAMILY_CHAR, 0)
+ MockedStyleSheet(const rtl::OUString& name, SfxStyleFamily fam = SFX_STYLE_FAMILY_CHAR)
+ : SfxStyleSheetBase(name, NULL, fam, 0)
{;}
};
@@ -36,6 +36,7 @@ class IndexedStyleSheetsTest : public CppUnit::TestFixture
void RemovingStyleSheetWhichIsNotAvailableHasNoEffect();
void StyleSheetsCanBeRetrievedByTheirName();
void KnowsThatItStoresAStyleSheet();
+ void PositionCanBeQueriedByFamily();
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE(IndexedStyleSheetsTest);
@@ -47,6 +48,7 @@ class IndexedStyleSheetsTest : public CppUnit::TestFixture
CPPUNIT_TEST(RemovingStyleSheetWhichIsNotAvailableHasNoEffect);
CPPUNIT_TEST(StyleSheetsCanBeRetrievedByTheirName);
CPPUNIT_TEST(KnowsThatItStoresAStyleSheet);
+ CPPUNIT_TEST(PositionCanBeQueriedByFamily);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
@@ -151,6 +153,27 @@ void IndexedStyleSheetsTest::KnowsThatItStoresAStyleSheet()
true, iss.HasStyleSheet(sheet2));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Does not find style sheet which is not stored and has the same name as a stored.",
false, iss.HasStyleSheet(sheet4));
+}
+
+void IndexedStyleSheetsTest::PositionCanBeQueriedByFamily()
+{
+ rtl::OUString name1("name1");
+ rtl::OUString name2("name2");
+ rtl::OUString name3("name3");
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(name1, SFX_STYLE_FAMILY_CHAR));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(name2, SFX_STYLE_FAMILY_PARA));
+ rtl::Reference<SfxStyleSheetBase> sheet3(new MockedStyleSheet(name3, SFX_STYLE_FAMILY_CHAR));
+
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ iss.AddStyleSheet(sheet2);
+ iss.AddStyleSheet(sheet3);
+
+ const std::vector<unsigned>& v = iss.GetStyleSheetPositionsByFamily(SFX_STYLE_FAMILY_CHAR);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Separation by family works.", static_cast<size_t>(2), v.size());
+
+ const std::vector<unsigned>& w = iss.GetStyleSheetPositionsByFamily(SFX_STYLE_FAMILY_ALL);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Wildcard works for family queries.", static_cast<size_t>(3), w.size());
}
diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx
index 087f817..7b9f7b6 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -16,27 +16,64 @@
using rtl::OUString;
+
+namespace {
+const size_t NUMBER_OF_FAMILIES = 6;
+size_t family_to_index(SfxStyleFamily family)
+{
+ switch (family) {
+ case SFX_STYLE_FAMILY_CHAR:
+ return 0;
+ case SFX_STYLE_FAMILY_PARA:
+ return 1;
+ case SFX_STYLE_FAMILY_FRAME:
+ return 2;
+ case SFX_STYLE_FAMILY_PAGE:
+ return 3;
+ case SFX_STYLE_FAMILY_PSEUDO:
+ return 4;
+ case SFX_STYLE_FAMILY_ALL:
+ return 5;
+ }
+ assert(false); // only for compiler warning. all cases are handled in the switch
+ return 0;
+}
+}
+
namespace svl {
IndexedStyleSheets::IndexedStyleSheets()
-{;}
+{
+ for (size_t i = 0; i < NUMBER_OF_FAMILIES; i++) {
+ mStyleSheetPositionsByFamily.push_back(std::vector<unsigned>());
+ }
+;}
void
-IndexedStyleSheets::Register(const rtl::OUString& name, unsigned pos)
+IndexedStyleSheets::Register(const SfxStyleSheetBase& style, unsigned pos)
{
- mPositionsByName.insert(std::make_pair(name, pos));
+ mPositionsByName.insert(std::make_pair(style.GetName(), pos));
+ size_t position = family_to_index(style.GetFamily());
+ mStyleSheetPositionsByFamily.at(position).push_back(pos);
+ size_t positionForFamilyAll = family_to_index(SFX_STYLE_FAMILY_ALL);
+ mStyleSheetPositionsByFamily.at(positionForFamilyAll).push_back(pos);
}
void
IndexedStyleSheets::Reindex()
{
mPositionsByName.clear();
+ mStyleSheetPositionsByFamily.clear();
+ for (size_t i = 0; i < NUMBER_OF_FAMILIES; i++) {
+ mStyleSheetPositionsByFamily.push_back(std::vector<unsigned>());
+ }
+
unsigned i = 0;
for (VectorType::const_iterator it = mStyleSheets.begin();
it != mStyleSheets.end(); ++it) {
SfxStyleSheetBase* p = it->get();
- Register(p->GetName(), i);
+ Register(*p, i);
++i;
}
}
@@ -53,7 +90,7 @@ IndexedStyleSheets::AddStyleSheet(rtl::Reference< SfxStyleSheetBase > style)
if (!HasStyleSheet(style)) {
mStyleSheets.push_back(style);
// since we just added an element to the vector, we can safely do -1 as it will always be >= 1
- Register(style->GetName(), mStyleSheets.size()-1);
+ Register(*style, mStyleSheets.size()-1);
}
}
@@ -207,6 +244,13 @@ IndexedStyleSheets::FindPositionsByPredicate(StyleSheetPredicate& predicate) con
return r;
}
+const std::vector<unsigned>&
+IndexedStyleSheets::GetStyleSheetPositionsByFamily(SfxStyleFamily e) const
+{
+ size_t position = family_to_index(e);
+ return mStyleSheetPositionsByFamily.at(position);
+}
+
} /* namespace svl */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index d6c9a30..369bebe 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -426,6 +426,10 @@ sal_uInt16 SfxStyleSheetIterator::Count()
{
n = (sal_uInt16) pBasePool->mIndexedStyleSheets->GetNumberOfStyleSheets();
}
+ else if(nMask == SFXSTYLEBIT_ALL)
+ {
+ n = static_cast<sal_uInt16>(pBasePool->mIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily).size());
+ }
else
{
DoesStyleMatchStyleSheetPredicate predicate(this);
@@ -442,6 +446,15 @@ SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx)
retval = pBasePool->mIndexedStyleSheets->GetStyleSheetByPosition(nIdx).get();
nAktPosition = nIdx;
}
+ else if(nMask == SFXSTYLEBIT_ALL)
+ {
+ rtl::Reference< SfxStyleSheetBase > ref =
+ pBasePool->mIndexedStyleSheets->GetStyleSheetByPosition(
+ pBasePool->mIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily).at(nIdx))
+ ;
+ retval = ref.get();
+ nAktPosition = nIdx;
+ }
else
{
DoesStyleMatchStyleSheetPredicate predicate(this);
@@ -464,7 +477,12 @@ SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx)
SfxStyleSheetBase* SfxStyleSheetIterator::First()
{
- return operator[](0);
+ if (Count() != 0) {
+ return operator[](0);
+ }
+ else {
+ return NULL;
+ }
}
@@ -482,6 +500,17 @@ SfxStyleSheetBase* SfxStyleSheetIterator::Next()
retval = pBasePool->mIndexedStyleSheets->GetStyleSheetByPosition(nAktPosition).get();
}
}
+ else if(nMask == SFXSTYLEBIT_ALL)
+ {
+ unsigned newPosition = nAktPosition +1;
+ const std::vector<unsigned>& familyVector = pBasePool->mIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily);
+ if (familyVector.size() > newPosition)
+ {
+ nAktPosition = newPosition;
+ unsigned stylePosition = familyVector.at(newPosition);
+ retval = pBasePool->mIndexedStyleSheets->GetStyleSheetByPosition(stylePosition).get();
+ }
+ }
else
{
DoesStyleMatchStyleSheetPredicate predicate(this);
More information about the Libreoffice-commits
mailing list