1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <TableConnectionData.hxx>
22 #include <osl/diagnose.h>
24 using namespace dbaui
;
26 OTableConnectionData::OTableConnectionData()
31 OTableConnectionData::OTableConnectionData(TTableWindowData::value_type _pReferencingTable
32 ,TTableWindowData::value_type _pReferencedTable
)
33 :m_pReferencingTable(std::move(_pReferencingTable
))
34 ,m_pReferencedTable(std::move(_pReferencedTable
))
39 void OTableConnectionData::Init()
41 // initialise linedatalist with defaults
42 OSL_ENSURE(m_vConnLineData
.empty(), "OTableConnectionData::Init() : call only with empty line list!");
44 // this creates the defaults
47 OTableConnectionData::OTableConnectionData( const OTableConnectionData
& rConnData
)
52 void OTableConnectionData::CopyFrom(const OTableConnectionData
& rSource
)
55 // here I revert to the (non-virtual) operator =, which only copies my members
58 OTableConnectionData::~OTableConnectionData()
60 // delete LineDataList
61 OConnectionLineDataVec().swap(m_vConnLineData
);
64 OTableConnectionData
& OTableConnectionData::operator=( const OTableConnectionData
& rConnData
)
66 if (&rConnData
== this)
69 m_pReferencingTable
= rConnData
.m_pReferencingTable
;
70 m_pReferencedTable
= rConnData
.m_pReferencedTable
;
71 m_aConnName
= rConnData
.m_aConnName
;
77 for (auto const& elem
: rConnData
.GetConnLineDataList())
78 m_vConnLineData
.push_back(new OConnectionLineData(*elem
));
83 void OTableConnectionData::SetConnLine( sal_uInt16 nIndex
, const OUString
& rSourceFieldName
, const OUString
& rDestFieldName
)
85 if (sal_uInt16(m_vConnLineData
.size()) < nIndex
)
88 // == still allowed, this corresponds to an Append
90 if (m_vConnLineData
.size() == nIndex
)
92 AppendConnLine(rSourceFieldName
, rDestFieldName
);
96 OConnectionLineDataRef pConnLineData
= m_vConnLineData
[nIndex
];
97 OSL_ENSURE(pConnLineData
!= nullptr, "OTableConnectionData::SetConnLine : have invalid LineData object");
99 pConnLineData
->SetSourceFieldName( rSourceFieldName
);
100 pConnLineData
->SetDestFieldName( rDestFieldName
);
103 bool OTableConnectionData::AppendConnLine( const OUString
& rSourceFieldName
, const OUString
& rDestFieldName
)
105 for (auto const& elem
: m_vConnLineData
)
107 if(elem
->GetDestFieldName() == rDestFieldName
&& elem
->GetSourceFieldName() == rSourceFieldName
)
110 OConnectionLineDataRef pNew
= new OConnectionLineData(rSourceFieldName
, rDestFieldName
);
114 m_vConnLineData
.push_back(pNew
);
118 void OTableConnectionData::ResetConnLines()
120 OConnectionLineDataVec().swap(m_vConnLineData
);
123 std::shared_ptr
<OTableConnectionData
> OTableConnectionData::NewInstance() const
125 return std::make_shared
<OTableConnectionData
>();
128 OConnectionLineDataVec::size_type
OTableConnectionData::normalizeLines()
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
;)
135 if(m_vConnLineData
[i
]->GetSourceFieldName().isEmpty() && m_vConnLineData
[i
]->GetDestFieldName().isEmpty())
137 m_vConnLineData
.erase(m_vConnLineData
.begin()+i
);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */