LibreOffice Module sdext (master)  1
optimizationstats.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include "optimizationstats.hxx"
22 #include <com/sun/star/awt/Size.hpp>
23 #include <com/sun/star/drawing/XShapes.hpp>
24 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
25 
27 
28 #include <algorithm>
29 
30 
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::frame;
34 using namespace ::com::sun::star::drawing;
35 using namespace ::com::sun::star::beans;
36 
37 
39 {
40 }
41 
42 
44 {
45  maStats[ eStat ] = rStatValue;
46 }
47 
48 
50 {
51  std::map< PPPOptimizerTokenEnum, uno::Any >::const_iterator aIter( maStats.find( eStat ) );
52  return aIter != maStats.end() ? &((*aIter).second) : nullptr;
53 }
54 
55 
56 css::beans::PropertyValues OptimizationStats::GetStatusSequence()
57 {
58  uno::Sequence< PropertyValue > aStatsSequence( maStats.size() );
59  std::transform(maStats.begin(), maStats.end(), aStatsSequence.getArray(),
60  [](const auto& rEntry)
61  { return comphelper::makePropertyValue(TKGet( rEntry.first ), rEntry.second); });
62  return aStatsSequence;
63 }
64 
65 
66 void OptimizationStats::InitializeStatusValues( const uno::Sequence< PropertyValue >& rOptimizationStats )
67 {
68  for( const auto& rStat : rOptimizationStats )
69  maStats[ TKGet( rStat.Name ) ] = rStat.Value;
70 }
71 
72 
73 void OptimizationStats::InitializeStatusValuesFromDocument( const Reference< XModel >& rxModel )
74 {
75  try
76  {
77  Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
78  Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
79  SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) );
80  }
81  catch ( Exception& )
82  {
83  }
84 }
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Any * GetStatusValue(const PPPOptimizerTokenEnum eStat) const
void InitializeStatusValues(const css::uno::Sequence< css::beans::PropertyValue > &rOptimizationStats)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
void SetStatusValue(const PPPOptimizerTokenEnum eStat, const css::uno::Any &rStatValue)
void InitializeStatusValuesFromDocument(const css::uno::Reference< css::frame::XModel > &rxModel)
PPPOptimizerTokenEnum
std::map< PPPOptimizerTokenEnum, css::uno::Any > maStats
PPPOptimizerTokenEnum TKGet(const OUString &rToken)
css::beans::PropertyValues GetStatusSequence()