LibreOffice Module forms (master) 1
model_helper.hxx
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#pragma once
20
21
22// some helper definitions that must be available for model.cxx and
23// model_ui.cxx
24
25
26#include "namedcollection.hxx"
27#include "binding.hxx"
28#include "submission.hxx"
29#include "unohelper.hxx"
30
31#include <com/sun/star/uno/Reference.hxx>
32#include <com/sun/star/uno/Sequence.hxx>
33#include <com/sun/star/lang/XUnoTunnel.hpp>
34#include <com/sun/star/beans/XPropertySet.hpp>
35#include <com/sun/star/beans/PropertyValue.hpp>
37
38namespace xforms
39{
40 class Model;
41}
42
43
44// BindingCollection
45
46
47namespace xforms
48{
49
50class BindingCollection : public NamedCollection<css::uno::Reference<css::beans::XPropertySet> >
51{
53
54public:
55 explicit BindingCollection( Model* pModel ) : mpModel( pModel ) {}
56
57 virtual bool isValid( const T& t ) const override
58 {
59 return comphelper::getFromUnoTunnel<Binding>( t ) != nullptr;
60 }
61
62protected:
63 virtual void _insert( const T& t ) override
64 {
65 auto pBinding = comphelper::getFromUnoTunnel<Binding>( t );
66 OSL_ENSURE( pBinding != nullptr, "invalid item?" );
67 pBinding->_setModel( css::uno::Reference<css::xforms::XModel>( mpModel ) );
68 }
69
70 virtual void _remove( const T& t ) override
71 {
72 auto pBinding = comphelper::getFromUnoTunnel<Binding>( t );
73 OSL_ENSURE( pBinding != nullptr, "invalid item?" );
74 pBinding->_setModel( css::uno::Reference<css::xforms::XModel>() );
75 }
76};
77
78class SubmissionCollection : public NamedCollection<css::uno::Reference<css::beans::XPropertySet> >
79{
81
82public:
83 explicit SubmissionCollection( Model* pModel ) : mpModel( pModel ) {}
84
85 virtual bool isValid( const T& t ) const override
86 {
87 return dynamic_cast<Submission*>( t.get() ) != nullptr;
88 }
89
90protected:
91 virtual void _insert( const T& t ) override
92 {
93 auto pSubmission = dynamic_cast<Submission*>( t.get() );
94 assert(pSubmission && "invalid item?");
95 pSubmission->setModel( mpModel );
96 }
97
98 virtual void _remove( const T& t ) override
99 {
100 auto pSubmission = dynamic_cast<Submission*>( t.get() );
101 assert(pSubmission && "invalid item?");
102 pSubmission->setModel( nullptr );
103 }
104};
105
106class InstanceCollection : public Collection<css::uno::Sequence<css::beans::PropertyValue> >
107{
108public:
109 virtual bool isValid( const T& t ) const override
110 {
111 for( const css::beans::PropertyValue& rProp : t )
112 {
113 if (rProp.Name == "Instance" )
114 return true;
115 }
116 return false;
117 }
118};
119
120
121// helper functions
122
123
124sal_Int32 lcl_findInstance( const InstanceCollection*,
125 std::u16string_view );
126
127
128// get values from Sequence<PropertyValue> describing an Instance
130 const css::uno::Sequence<css::beans::PropertyValue>&,
131 OUString* pID,
132 css::uno::Reference<css::xml::dom::XDocument>*,
133 OUString* pURL,
134 bool* pURLOnce );
135
136// set values on Sequence<PropertyValue> for an Instance
138 css::uno::Sequence<css::beans::PropertyValue>&,
139 const OUString* pID,
140 const css::uno::Reference<css::xml::dom::XDocument>*,
141 const OUString* pURL,
142 const bool* pURLOnce );
143
144} // namespace xforms
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
css::uno::Sequence< css::beans::PropertyValue > T
Definition: collection.hxx:51
virtual bool isValid(const T &t) const override
virtual void _insert(const T &t) override
BindingCollection(Model *pModel)
virtual void _remove(const T &t) override
virtual bool isValid(const T &t) const override
called before insertion to determine whether item is valid
SubmissionCollection(Model *pModel)
virtual void _insert(const T &t) override
virtual bool isValid(const T &t) const override
virtual void _remove(const T &t) override
void getInstanceData(const css::uno::Sequence< css::beans::PropertyValue > &, OUString *pID, css::uno::Reference< css::xml::dom::XDocument > *, OUString *pURL, bool *pURLOnce)
sal_Int32 lcl_findInstance(const InstanceCollection *, std::u16string_view)
Definition: model_ui.cxx:423
void setInstanceData(css::uno::Sequence< css::beans::PropertyValue > &, const OUString *pID, const css::uno::Reference< css::xml::dom::XDocument > *, const OUString *pURL, const bool *pURLOnce)