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"
21 #include <tools/debug.hxx>
22 #include <osl/diagnose.h>
24 using namespace dbaui
;
26 // class OTableConnectionData
27 OTableConnectionData::OTableConnectionData()
32 OTableConnectionData::OTableConnectionData(const TTableWindowData::value_type
& _pReferencingTable
33 ,const TTableWindowData::value_type
& _pReferencedTable
34 ,const OUString
& rConnName
)
35 :m_pReferencingTable(_pReferencingTable
)
36 ,m_pReferencedTable(_pReferencedTable
)
37 ,m_aConnName( rConnName
)
42 void OTableConnectionData::Init()
44 // initialise linedatalist with defaults
45 OSL_ENSURE(m_vConnLineData
.empty(), "OTableConnectionData::Init() : nur mit leere Linienliste aufzurufen !");
47 // this creates the defaults
50 OTableConnectionData::OTableConnectionData( const OTableConnectionData
& rConnData
)
55 void OTableConnectionData::CopyFrom(const OTableConnectionData
& rSource
)
58 // here I revert to the (non-virtual) operator =, which only copies my members
61 OTableConnectionData::~OTableConnectionData()
63 // delete LineDataList
64 OConnectionLineDataVec().swap(m_vConnLineData
);
67 OTableConnectionData
& OTableConnectionData::operator=( const OTableConnectionData
& rConnData
)
69 if (&rConnData
== this)
72 m_pReferencingTable
= rConnData
.m_pReferencingTable
;
73 m_pReferencedTable
= rConnData
.m_pReferencedTable
;
74 m_aConnName
= rConnData
.GetConnName();
80 const OConnectionLineDataVec
& rLineData
= rConnData
.GetConnLineDataList();
82 OConnectionLineDataVec::const_iterator aIter
= rLineData
.begin();
83 OConnectionLineDataVec::const_iterator aEnd
= rLineData
.end();
84 for(;aIter
!= aEnd
;++aIter
)
85 m_vConnLineData
.push_back(new OConnectionLineData(**aIter
));
90 void OTableConnectionData::SetConnLine( sal_uInt16 nIndex
, const OUString
& rSourceFieldName
, const OUString
& rDestFieldName
)
92 if (sal_uInt16(m_vConnLineData
.size()) < nIndex
)
95 // == still allowed, this corresponds to an Append
97 if (m_vConnLineData
.size() == nIndex
)
99 AppendConnLine(rSourceFieldName
, rDestFieldName
);
103 OConnectionLineDataRef pConnLineData
= m_vConnLineData
[nIndex
];
104 OSL_ENSURE(pConnLineData
!= nullptr, "OTableConnectionData::SetConnLine : habe ungueltiges LineData-Objekt");
106 pConnLineData
->SetSourceFieldName( rSourceFieldName
);
107 pConnLineData
->SetDestFieldName( rDestFieldName
);
110 bool OTableConnectionData::AppendConnLine( const OUString
& rSourceFieldName
, const OUString
& rDestFieldName
)
112 OConnectionLineDataVec::const_iterator aIter
= m_vConnLineData
.begin();
113 OConnectionLineDataVec::const_iterator aEnd
= m_vConnLineData
.end();
114 for(;aIter
!= aEnd
;++aIter
)
116 if((*aIter
)->GetDestFieldName() == rDestFieldName
&& (*aIter
)->GetSourceFieldName() == rSourceFieldName
)
121 OConnectionLineDataRef pNew
= new OConnectionLineData(rSourceFieldName
, rDestFieldName
);
125 m_vConnLineData
.push_back(pNew
);
130 void OTableConnectionData::ResetConnLines()
132 OConnectionLineDataVec().swap(m_vConnLineData
);
135 OConnectionLineDataRef
OTableConnectionData::CreateLineDataObj()
137 return new OConnectionLineData();
140 OTableConnectionData
* OTableConnectionData::NewInstance() const
142 return new OTableConnectionData();
145 OConnectionLineDataVec::size_type
OTableConnectionData::normalizeLines()
147 // remove empty lines
148 OConnectionLineDataVec::size_type nCount
= m_vConnLineData
.size();
149 OConnectionLineDataVec::size_type nRet
= nCount
;
150 for(OConnectionLineDataVec::size_type i
= 0; i
< nCount
;)
152 if(m_vConnLineData
[i
]->GetSourceFieldName().isEmpty() && m_vConnLineData
[i
]->GetDestFieldName().isEmpty())
154 OConnectionLineDataRef pData
= m_vConnLineData
[i
];
155 m_vConnLineData
.erase(m_vConnLineData
.begin()+i
);
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */