LibreOffice Module reportdesign (master)  1
RptModel.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 #include <RptModel.hxx>
21 #include <RptPage.hxx>
23 #include <vcl/svapp.hxx>
24 
25 #include <UndoEnv.hxx>
26 #include <ReportUndoFactory.hxx>
27 #include <ReportDefinition.hxx>
28 
29 #include <RptDef.hxx>
30 #include <strings.hxx>
31 #include <FixedLine.hxx>
32 #include <FormattedField.hxx>
33 #include <FixedText.hxx>
34 #include <ImageControl.hxx>
35 #include <Shape.hxx>
36 
37 namespace rptui
38 {
39 using namespace reportdesign;
40 using namespace com::sun::star;
41 
42 
44 : SdrModel(
45  nullptr,
46  _pReportDefinition)
47  ,m_pController(nullptr)
48  ,m_pReportDefinition(_pReportDefinition)
49 {
50  m_xUndoEnv = new OXUndoEnvironment(*this);
52 }
53 
54 
56 {
58 }
59 
61 {
62  m_pReportDefinition = nullptr;
63  m_pController = nullptr;
64  m_xUndoEnv->EndListening( *this );
67 }
68 
70 {
71  OSL_FAIL("Who called me!");
72  return nullptr;
73 }
74 
75 
76 void OReportModel::SetChanged( bool bChanged )
77 {
78  SdrModel::SetChanged( bChanged );
79  SetModified( bChanged );
80 }
81 
82 
83 void OReportModel::SetModified(bool _bModified)
84 {
85  if ( m_pController )
86  m_pController->setModified(_bModified);
87 }
88 
90 {
91  rtl::Reference<OReportPage> pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum).get());
92  return pPage;
93 }
94 
95 OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
96 {
97  SolarMutexGuard aSolarGuard;
98  rtl::Reference<OReportPage> pPage = new OReportPage( *this ,_xSection);
99  InsertPage(pPage.get());
100  m_xUndoEnv->AddSection(_xSection);
101  return pPage.get();
102 }
103 
104 OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
105 {
106  OReportPage* pPage = nullptr;
107  sal_uInt16 nCount = GetPageCount();
108  for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
109  {
110  OReportPage* pRptPage = dynamic_cast<OReportPage*>( GetPage(i) );
111  if ( pRptPage && pRptPage->getSection() == _xSection )
112  pPage = pRptPage;
113  }
114  return pPage;
115 }
116 
118 {
119  uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
120  if ( xReportDefinition.is() )
121  return static_cast<SvxNumType>(getStyleProperty<sal_Int16>(xReportDefinition,PROPERTY_NUMBERINGTYPE));
122  return SVX_NUM_ARABIC;
123 }
124 
125 
126 uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
127 {
128  uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
129  OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
130  return xReportDefinition;
131 }
132 
133 uno::Reference< uno::XInterface > OReportModel::createUnoModel()
134 {
135  return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
136 }
137 
138 uno::Reference< uno::XInterface > OReportModel::createShape(const OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
139 {
140  uno::Reference< uno::XInterface > xRet;
141  if ( _rShape.is() )
142  {
143  if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
144  {
145  uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
146  xRet = xProp;
147  if ( _rShape.is() )
148  throw uno::Exception("no shape", nullptr);
149  xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::makeAny(uno::Reference< util::XNumberFormatsSupplier >(*m_pReportDefinition,uno::UNO_QUERY)) );
150  }
151  else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
152  {
153  xRet = static_cast<cppu::OWeakObject*>(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
154  if ( _rShape.is() )
155  throw uno::Exception("no shape", nullptr);
156  }
157  else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
158  {
159  xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
160  if ( _rShape.is() )
161  throw uno::Exception("no shape", nullptr);
162  }
163  else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
164  {
166  if ( _rShape.is() )
167  throw uno::Exception("no shape", nullptr);
168  }
169  else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
170  {
172  if ( _rShape.is() )
173  throw uno::Exception("no shape", nullptr);
174  }
175  else if ( _rShape.is() )
176  {
177  xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
178  if ( _rShape.is() )
179  throw uno::Exception("no shape", nullptr);
180  }
181  }
182  return xRet;
183 }
184 
185 } //rptui
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setModified(sal_Bool bModified) override
#define SERVICE_IMAGECONTROL
Definition: strings.hxx:24
implementation of a
Definition: FixedText.hxx:43
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum) override
Definition: RptModel.cxx:89
#define PROPERTY_NUMBERINGTYPE
Definition: strings.hxx:213
OReportPage * getPage(const css::uno::Reference< css::report::XSection > &_xSection)
returns the page which belongs to a section
Definition: RptModel.cxx:104
virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override
Definition: RptModel.cxx:133
const css::uno::Reference< css::report::XSection > & getSection() const
Definition: RptPage.hxx:82
virtual ~OReportModel() override
Definition: RptModel.cxx:55
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
SvxNumType
css::uno::Reference< css::uno::XInterface > createShape(const OUString &aServiceSpecifier, css::uno::Reference< css::drawing::XShape > &_rShape, sal_Int32 nOrientation=-1)
Definition: RptModel.cxx:138
friend class OReportPage
Definition: RptModel.hxx:43
css::uno::Reference< css::uno::XComponentContext > getContext()
int nCount
SVX_NUM_ARABIC
virtual void SetChanged(bool bFlg=true)
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum)
virtual SvxNumType GetPageNumType() const override
Definition: RptModel.cxx:117
#define SERVICE_FIXEDLINE
Definition: strings.hxx:29
#define SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
implementation of a
int i
implementation of a
Definition: FixedLine.hxx:42
implementation of a
Definition: Shape.hxx:42
rtl::Reference< OXUndoEnvironment > m_xUndoEnv
Definition: RptModel.hxx:46
const SdrPage * GetPage(sal_uInt16 nPgNum) const
::reportdesign::OReportDefinition * m_pReportDefinition
Definition: RptModel.hxx:48
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
Definition: RptModel.cxx:69
#define PROPERTY_FORMATSSUPPLIER
Definition: strings.hxx:97
void SetSdrUndoFactory(SdrUndoFactory *pUndoFactory)
::dbaui::DBSubComponentController * m_pController
Definition: RptModel.hxx:47
void detachController()
Definition: RptModel.cxx:60
OReportModel(const OReportModel &)=delete
void SetModified(bool _bModified)
Definition: RptModel.cxx:83
virtual void SetChanged(bool bFlg=true) override
Definition: RptModel.cxx:76
#define SERVICE_REPORTDEFINITION
Definition: strings.hxx:27
css::uno::Reference< css::report::XReportDefinition > getReportDefinition() const
returns the XReportDefinition which the OReportModel belongs to
Definition: RptModel.cxx:126
void ClearUndoBuffer()
OReportPage * createNewPage(const css::uno::Reference< css::report::XSection > &_xSection)
Definition: RptModel.cxx:95
sal_uInt16 GetPageCount() const
#define SERVICE_FIXEDTEXT
Definition: strings.hxx:22