Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableConnectionData.cxx
blob43fc4eed888062d1cec263c08ee7b49a505b26df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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()
29 Init();
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 )
39 Init();
42 void OTableConnectionData::Init()
44 // initialise linedatalist with defaults
45 OSL_ENSURE(m_vConnLineData.empty(), "OTableConnectionData::Init() : nur mit leere Linienliste aufzurufen !");
46 ResetConnLines();
47 // this creates the defaults
50 OTableConnectionData::OTableConnectionData( const OTableConnectionData& rConnData )
52 *this = rConnData;
55 void OTableConnectionData::CopyFrom(const OTableConnectionData& rSource)
57 *this = 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)
70 return *this;
72 m_pReferencingTable = rConnData.m_pReferencingTable;
73 m_pReferencedTable = rConnData.m_pReferencedTable;
74 m_aConnName = rConnData.GetConnName();
76 // clear line list
77 ResetConnLines();
79 // and copy
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));
87 return *this;
90 bool OTableConnectionData::SetConnLine( sal_uInt16 nIndex, const OUString& rSourceFieldName, const OUString& rDestFieldName )
92 if (sal_uInt16(m_vConnLineData.size()) < nIndex)
93 return false;
95 // == still allowed, this correponds to a Append
97 if (m_vConnLineData.size() == nIndex)
98 return AppendConnLine(rSourceFieldName, rDestFieldName);
100 OConnectionLineDataRef pConnLineData = m_vConnLineData[nIndex];
101 OSL_ENSURE(pConnLineData != NULL, "OTableConnectionData::SetConnLine : habe ungueltiges LineData-Objekt");
103 pConnLineData->SetSourceFieldName( rSourceFieldName );
104 pConnLineData->SetDestFieldName( rDestFieldName );
106 return true;
109 bool OTableConnectionData::AppendConnLine( const OUString& rSourceFieldName, const OUString& rDestFieldName )
111 OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
112 OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
113 for(;aIter != aEnd;++aIter)
115 if((*aIter)->GetDestFieldName() == rDestFieldName && (*aIter)->GetSourceFieldName() == rSourceFieldName)
116 break;
118 if(aIter == aEnd)
120 OConnectionLineDataRef pNew = new OConnectionLineData(rSourceFieldName, rDestFieldName);
121 if (!pNew.is())
122 return false;
124 m_vConnLineData.push_back(pNew);
126 return true;
129 void OTableConnectionData::ResetConnLines()
131 OConnectionLineDataVec().swap(m_vConnLineData);
134 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj()
136 return new OConnectionLineData();
139 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj( const OConnectionLineData& rConnLineData )
141 return new OConnectionLineData( rConnLineData );
144 OTableConnectionData* OTableConnectionData::NewInstance() const
146 return new OTableConnectionData();
149 OConnectionLineDataVec::size_type OTableConnectionData::normalizeLines()
151 // remove empty lines
152 OConnectionLineDataVec::size_type nCount = m_vConnLineData.size();
153 OConnectionLineDataVec::size_type nRet = nCount;
154 for(OConnectionLineDataVec::size_type i = 0; i < nCount;)
156 if(m_vConnLineData[i]->GetSourceFieldName().isEmpty() && m_vConnLineData[i]->GetDestFieldName().isEmpty())
158 OConnectionLineDataRef pData = m_vConnLineData[i];
159 m_vConnLineData.erase(m_vConnLineData.begin()+i);
160 --nCount;
161 if (i < nRet)
162 nRet=i;
164 else
165 ++i;
167 return nRet;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */