summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-02-14 09:11:43 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-02-15 07:51:58 +0100
commit954397df73b182e105e3ae5dff40c36a96239b08 (patch)
tree61db673b2337dc86a9c1f05860bd8f0fc827b5e7
parentb104e6e979bab16605840c2a14914917d5e552b3 (diff)
loplugin:flatten in sd/source/ui/sidebar
Change-Id: I1a636fdfc505e7927b8833ad55110f6ed8fe360d Reviewed-on: https://gerrit.libreoffice.org/67832 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sd/source/ui/sidebar/MasterPageContainer.cxx58
-rw-r--r--sd/source/ui/sidebar/MasterPageObserver.cxx138
-rw-r--r--sd/source/ui/sidebar/MasterPagesSelector.cxx56
-rw-r--r--sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx49
4 files changed, 150 insertions, 151 deletions
diff --git a/sd/source/ui/sidebar/MasterPageContainer.cxx b/sd/source/ui/sidebar/MasterPageContainer.cxx
index 1368400e6626..f96cb090ad25 100644
--- a/sd/source/ui/sidebar/MasterPageContainer.cxx
+++ b/sd/source/ui/sidebar/MasterPageContainer.cxx
@@ -264,24 +264,24 @@ void MasterPageContainer::AcquireToken (Token aToken)
void MasterPageContainer::ReleaseToken (Token aToken)
{
SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
- if (pDescriptor.get() != nullptr)
- {
- OSL_ASSERT(pDescriptor->mnUseCount>0);
- --pDescriptor->mnUseCount;
- if (pDescriptor->mnUseCount <= 0)
- {
- switch (pDescriptor->meOrigin)
- {
- case DEFAULT:
- case TEMPLATE:
- default:
- break;
+ if (pDescriptor.get() == nullptr)
+ return;
- case MASTERPAGE:
- mpImpl->ReleaseDescriptor(aToken);
- break;
- }
- }
+ OSL_ASSERT(pDescriptor->mnUseCount>0);
+ --pDescriptor->mnUseCount;
+ if (pDescriptor->mnUseCount > 0)
+ return;
+
+ switch (pDescriptor->meOrigin)
+ {
+ case DEFAULT:
+ case TEMPLATE:
+ default:
+ break;
+
+ case MASTERPAGE:
+ mpImpl->ReleaseDescriptor(aToken);
+ break;
}
}
@@ -522,21 +522,21 @@ void MasterPageContainer::Implementation::LateInit()
{
const ::osl::MutexGuard aGuard (maMutex);
- if (meInitializationState == NOT_INITIALIZED)
- {
- meInitializationState = INITIALIZING;
+ if (meInitializationState != NOT_INITIALIZED)
+ return;
- OSL_ASSERT(Instance().get()==this);
- mpRequestQueue.reset(MasterPageContainerQueue::Create(
- std::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance())));
+ meInitializationState = INITIALIZING;
- mpFillerTask = ::sd::tools::TimerBasedTaskExecution::Create(
- std::shared_ptr<tools::AsynchronousTask>(new MasterPageContainerFiller(*this)),
- 5,
- 50);
+ OSL_ASSERT(Instance().get()==this);
+ mpRequestQueue.reset(MasterPageContainerQueue::Create(
+ std::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance())));
- meInitializationState = INITIALIZED;
- }
+ mpFillerTask = ::sd::tools::TimerBasedTaskExecution::Create(
+ std::shared_ptr<tools::AsynchronousTask>(new MasterPageContainerFiller(*this)),
+ 5,
+ 50);
+
+ meInitializationState = INITIALIZED;
}
void MasterPageContainer::Implementation::AddChangeListener (const Link<MasterPageContainerChangeEvent&,void>& rLink)
diff --git a/sd/source/ui/sidebar/MasterPageObserver.cxx b/sd/source/ui/sidebar/MasterPageObserver.cxx
index d13a418fc918..eee288d021c3 100644
--- a/sd/source/ui/sidebar/MasterPageObserver.cxx
+++ b/sd/source/ui/sidebar/MasterPageObserver.cxx
@@ -186,24 +186,24 @@ void MasterPageObserver::Implementation::AddEventListener (
if (::std::find (
maListeners.begin(),
maListeners.end(),
- rEventListener) == maListeners.end())
- {
- maListeners.push_back (rEventListener);
+ rEventListener) != maListeners.end())
+ return;
+
+ maListeners.push_back (rEventListener);
- // Tell the new listener about all the master pages that are
- // currently in use.
- for (const auto& rDocument : maUsedMasterPages)
+ // Tell the new listener about all the master pages that are
+ // currently in use.
+ for (const auto& rDocument : maUsedMasterPages)
+ {
+ ::std::set<OUString>::reverse_iterator aNameIterator;
+ for (aNameIterator=rDocument.second.rbegin();
+ aNameIterator!=rDocument.second.rend();
+ ++aNameIterator)
{
- ::std::set<OUString>::reverse_iterator aNameIterator;
- for (aNameIterator=rDocument.second.rbegin();
- aNameIterator!=rDocument.second.rend();
- ++aNameIterator)
- {
- MasterPageObserverEvent aEvent (
- MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS,
- *aNameIterator);
- SendEvent (aEvent);
- }
+ MasterPageObserverEvent aEvent (
+ MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS,
+ *aNameIterator);
+ SendEvent (aEvent);
}
}
}
@@ -223,31 +223,31 @@ void MasterPageObserver::Implementation::Notify(
const SfxHint& rHint)
{
const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>(&rHint);
- if (pSdrHint)
+ if (!pSdrHint)
+ return;
+
+ switch (pSdrHint->GetKind())
{
- switch (pSdrHint->GetKind())
- {
- case SdrHintKind::PageOrderChange:
- // Process the modified set of pages only when the number of
- // standard and notes master pages are equal. This test
- // filters out events that are sent in between the insertion
- // of a new standard master page and a new notes master
- // page.
- if (dynamic_cast< const SdDrawDocument *>( &rBroadcaster ) != nullptr)
+ case SdrHintKind::PageOrderChange:
+ // Process the modified set of pages only when the number of
+ // standard and notes master pages are equal. This test
+ // filters out events that are sent in between the insertion
+ // of a new standard master page and a new notes master
+ // page.
+ if (dynamic_cast< const SdDrawDocument *>( &rBroadcaster ) != nullptr)
+ {
+ SdDrawDocument& rDocument (
+ static_cast<SdDrawDocument&>(rBroadcaster));
+ if (rDocument.GetMasterSdPageCount(PageKind::Standard)
+ == rDocument.GetMasterSdPageCount(PageKind::Notes))
{
- SdDrawDocument& rDocument (
- static_cast<SdDrawDocument&>(rBroadcaster));
- if (rDocument.GetMasterSdPageCount(PageKind::Standard)
- == rDocument.GetMasterSdPageCount(PageKind::Notes))
- {
- AnalyzeUsedMasterPages (rDocument);
- }
+ AnalyzeUsedMasterPages (rDocument);
}
- break;
+ }
+ break;
- default:
- break;
- }
+ default:
+ break;
}
}
@@ -268,41 +268,41 @@ void MasterPageObserver::Implementation::AnalyzeUsedMasterPages (
std::vector<OUString> aRemovedMasterPages;
MasterPageContainer::iterator aOldMasterPagesDescriptor (
maUsedMasterPages.find(&rDocument));
- if (aOldMasterPagesDescriptor != maUsedMasterPages.end())
+ if (aOldMasterPagesDescriptor == maUsedMasterPages.end())
+ return;
+
+ // Send events about the newly used master pages.
+ ::std::set_difference (
+ aCurrentMasterPages.begin(),
+ aCurrentMasterPages.end(),
+ aOldMasterPagesDescriptor->second.begin(),
+ aOldMasterPagesDescriptor->second.end(),
+ std::back_inserter(aNewMasterPages));
+ for (auto& aNewMasterPage : aNewMasterPages)
{
- // Send events about the newly used master pages.
- ::std::set_difference (
- aCurrentMasterPages.begin(),
- aCurrentMasterPages.end(),
- aOldMasterPagesDescriptor->second.begin(),
- aOldMasterPagesDescriptor->second.end(),
- std::back_inserter(aNewMasterPages));
- for (auto& aNewMasterPage : aNewMasterPages)
- {
- MasterPageObserverEvent aEvent (
- MasterPageObserverEvent::ET_MASTER_PAGE_ADDED,
- aNewMasterPage);
- SendEvent (aEvent);
- }
-
- // Send events about master pages that are not used any longer.
- ::std::set_difference (
- aOldMasterPagesDescriptor->second.begin(),
- aOldMasterPagesDescriptor->second.end(),
- aCurrentMasterPages.begin(),
- aCurrentMasterPages.end(),
- std::back_inserter(aRemovedMasterPages));
- for (auto& aRemovedMasterPage : aRemovedMasterPages)
- {
- MasterPageObserverEvent aEvent (
- MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED,
- aRemovedMasterPage);
- SendEvent (aEvent);
- }
+ MasterPageObserverEvent aEvent (
+ MasterPageObserverEvent::ET_MASTER_PAGE_ADDED,
+ aNewMasterPage);
+ SendEvent (aEvent);
+ }
- // Store the new list of master pages.
- aOldMasterPagesDescriptor->second = aCurrentMasterPages;
+ // Send events about master pages that are not used any longer.
+ ::std::set_difference (
+ aOldMasterPagesDescriptor->second.begin(),
+ aOldMasterPagesDescriptor->second.end(),
+ aCurrentMasterPages.begin(),
+ aCurrentMasterPages.end(),
+ std::back_inserter(aRemovedMasterPages));
+ for (auto& aRemovedMasterPage : aRemovedMasterPages)
+ {
+ MasterPageObserverEvent aEvent (
+ MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED,
+ aRemovedMasterPage);
+ SendEvent (aEvent);
}
+
+ // Store the new list of master pages.
+ aOldMasterPagesDescriptor->second = aCurrentMasterPages;
}
void MasterPageObserver::Implementation::SendEvent (
diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx
index 9e3eb76c7fc5..1bf528861cc8 100644
--- a/sd/source/ui/sidebar/MasterPagesSelector.cxx
+++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx
@@ -466,40 +466,40 @@ void MasterPagesSelector::SetItem (
RemoveTokenToIndexEntry(nIndex,aToken);
- if (nIndex > 0)
+ if (nIndex <= 0)
+ return;
+
+ if (aToken != MasterPageContainer::NIL_TOKEN)
{
- if (aToken != MasterPageContainer::NIL_TOKEN)
- {
- Image aPreview (mpContainer->GetPreviewForToken(aToken));
- MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
+ Image aPreview (mpContainer->GetPreviewForToken(aToken));
+ MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
- if (aPreview.GetSizePixel().Width()>0)
+ if (aPreview.GetSizePixel().Width()>0)
+ {
+ if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
{
- if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
- {
- PreviewValueSet::SetItemImage(nIndex,aPreview);
- PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
- }
- else
- {
- PreviewValueSet::InsertItem (
- nIndex,
- aPreview,
- mpContainer->GetPageNameForToken(aToken),
- nIndex);
- }
- SetUserData(nIndex, std::make_unique<UserData>(nIndex,aToken));
-
- AddTokenToIndexEntry(nIndex,aToken);
+ PreviewValueSet::SetItemImage(nIndex,aPreview);
+ PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
}
+ else
+ {
+ PreviewValueSet::InsertItem (
+ nIndex,
+ aPreview,
+ mpContainer->GetPageNameForToken(aToken),
+ nIndex);
+ }
+ SetUserData(nIndex, std::make_unique<UserData>(nIndex,aToken));
- if (eState == MasterPageContainer::PS_CREATABLE)
- mpContainer->RequestPreview(aToken);
- }
- else
- {
- PreviewValueSet::RemoveItem(nIndex);
+ AddTokenToIndexEntry(nIndex,aToken);
}
+
+ if (eState == MasterPageContainer::PS_CREATABLE)
+ mpContainer->RequestPreview(aToken);
+ }
+ else
+ {
+ PreviewValueSet::RemoveItem(nIndex);
}
}
diff --git a/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx b/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx
index 2df198079bf5..cabb628a42d7 100644
--- a/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx
+++ b/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx
@@ -320,35 +320,34 @@ void RecentlyUsedMasterPages::AddMasterPage (
// For the page to be inserted the token has to be valid and the page
// has to have a valid URL. This excludes master pages that do not come
// from template files.
- if (aToken != MasterPageContainer::NIL_TOKEN
- && !mpContainer->GetURLForToken(aToken).isEmpty())
+ if (aToken == MasterPageContainer::NIL_TOKEN
+ || mpContainer->GetURLForToken(aToken).isEmpty())
+ return;
+
+ MasterPageList::iterator aIterator (
+ ::std::find_if(mvMasterPages.begin(),mvMasterPages.end(),
+ Descriptor::TokenComparator(aToken)));
+ if (aIterator != mvMasterPages.end())
{
+ // When an entry for the given token already exists then remove
+ // it now and insert it later at the head of the list.
+ mvMasterPages.erase (aIterator);
+ }
- MasterPageList::iterator aIterator (
- ::std::find_if(mvMasterPages.begin(),mvMasterPages.end(),
- Descriptor::TokenComparator(aToken)));
- if (aIterator != mvMasterPages.end())
- {
- // When an entry for the given token already exists then remove
- // it now and insert it later at the head of the list.
- mvMasterPages.erase (aIterator);
- }
-
- mvMasterPages.insert(mvMasterPages.begin(),
- Descriptor(
- aToken,
- mpContainer->GetURLForToken(aToken),
- mpContainer->GetStyleNameForToken(aToken)));
-
- // Shorten list to maximal size.
- while (mvMasterPages.size() > gnMaxListSize)
- {
- mvMasterPages.pop_back ();
- }
+ mvMasterPages.insert(mvMasterPages.begin(),
+ Descriptor(
+ aToken,
+ mpContainer->GetURLForToken(aToken),
+ mpContainer->GetStyleNameForToken(aToken)));
- SavePersistentValues ();
- SendEvent();
+ // Shorten list to maximal size.
+ while (mvMasterPages.size() > gnMaxListSize)
+ {
+ mvMasterPages.pop_back ();
}
+
+ SavePersistentValues ();
+ SendEvent();
}
void RecentlyUsedMasterPages::ResolveList()