LibreOffice Module dbaccess (master) 1
TableConnectionData.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
21#include <utility>
22#include <osl/diagnose.h>
23
24using namespace dbaui;
25
26OTableConnectionData::OTableConnectionData()
27{
28 Init();
29}
30
31OTableConnectionData::OTableConnectionData(TTableWindowData::value_type _pReferencingTable
32 ,TTableWindowData::value_type _pReferencedTable )
33 :m_pReferencingTable(std::move(_pReferencingTable))
34 ,m_pReferencedTable(std::move(_pReferencedTable))
35{
36 Init();
37}
38
40{
41 // initialise linedatalist with defaults
42 OSL_ENSURE(m_vConnLineData.empty(), "OTableConnectionData::Init() : call only with empty line list!");
44 // this creates the defaults
45}
46
48{
49 *this = rConnData;
50}
51
53{
54 *this = rSource;
55 // here I revert to the (non-virtual) operator =, which only copies my members
56}
57
59{
60 // delete LineDataList
62}
63
65{
66 if (&rConnData == this)
67 return *this;
68
71 m_aConnName = rConnData.m_aConnName;
72
73 // clear line list
75
76 // and copy
77 for (auto const& elem : rConnData.GetConnLineDataList())
78 m_vConnLineData.push_back(new OConnectionLineData(*elem));
79
80 return *this;
81}
82
83void OTableConnectionData::SetConnLine( sal_uInt16 nIndex, const OUString& rSourceFieldName, const OUString& rDestFieldName )
84{
85 if (sal_uInt16(m_vConnLineData.size()) < nIndex)
86 return;
87
88 // == still allowed, this corresponds to an Append
89
90 if (m_vConnLineData.size() == nIndex)
91 {
92 AppendConnLine(rSourceFieldName, rDestFieldName);
93 return;
94 }
95
97 OSL_ENSURE(pConnLineData != nullptr, "OTableConnectionData::SetConnLine : have invalid LineData object");
98
99 pConnLineData->SetSourceFieldName( rSourceFieldName );
100 pConnLineData->SetDestFieldName( rDestFieldName );
101}
102
103bool OTableConnectionData::AppendConnLine( const OUString& rSourceFieldName, const OUString& rDestFieldName )
104{
105 for (auto const& elem : m_vConnLineData)
106 {
107 if(elem->GetDestFieldName() == rDestFieldName && elem->GetSourceFieldName() == rSourceFieldName)
108 return true;
109 }
110 OConnectionLineDataRef pNew = new OConnectionLineData(rSourceFieldName, rDestFieldName);
111 if (!pNew.is())
112 return false;
113
114 m_vConnLineData.push_back(pNew);
115 return true;
116}
117
119{
121}
122
123std::shared_ptr<OTableConnectionData> OTableConnectionData::NewInstance() const
124{
125 return std::make_shared<OTableConnectionData>();
126}
127
128OConnectionLineDataVec::size_type OTableConnectionData::normalizeLines()
129{
130 // remove empty lines
131 OConnectionLineDataVec::size_type nCount = m_vConnLineData.size();
132 OConnectionLineDataVec::size_type nRet = nCount;
133 for(OConnectionLineDataVec::size_type i = 0; i < nCount;)
134 {
135 if(m_vConnLineData[i]->GetSourceFieldName().isEmpty() && m_vConnLineData[i]->GetDestFieldName().isEmpty())
136 {
137 m_vConnLineData.erase(m_vConnLineData.begin()+i);
138 --nCount;
139 if (i < nRet)
140 nRet=i;
141 }
142 else
143 ++i;
144 }
145 return nRet;
146}
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the class OConnectionLineData contains the data of a connection e.g.
Contains all connection data which exists between two windows.
TTableWindowData::value_type m_pReferencedTable
virtual void CopyFrom(const OTableConnectionData &rSource)
initialise from a source (more comfortable than a virtual assignment operator)
virtual std::shared_ptr< OTableConnectionData > NewInstance() const
deliver a new instance of my own type
TTableWindowData::value_type m_pReferencingTable
void ResetConnLines()
Deletes list of ConnLines.
bool AppendConnLine(const OUString &rSourceFieldName, const OUString &rDestFieldName)
const OConnectionLineDataVec & GetConnLineDataList() const
void SetConnLine(sal_uInt16 nIndex, const OUString &rSourceFieldName, const OUString &rDestFieldName)
OConnectionLineDataVec::size_type normalizeLines()
moves the empty lines to the back removes duplicated empty lines
OConnectionLineDataVec m_vConnLineData
OTableConnectionData & operator=(const OTableConnectionData &rConnData)
int nCount
sal_Int32 nIndex
std::vector< OConnectionLineDataRef > OConnectionLineDataVec
int i