Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableConnectionData.cxx
blobaa524a5ac7f92ed50aa95646e5e0c0fa82ad44a3
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 <utility>
22 #include <osl/diagnose.h>
24 using namespace dbaui;
26 OTableConnectionData::OTableConnectionData()
28 Init();
31 OTableConnectionData::OTableConnectionData(TTableWindowData::value_type _pReferencingTable
32 ,TTableWindowData::value_type _pReferencedTable )
33 :m_pReferencingTable(std::move(_pReferencingTable))
34 ,m_pReferencedTable(std::move(_pReferencedTable))
36 Init();
39 void OTableConnectionData::Init()
41 // initialise linedatalist with defaults
42 OSL_ENSURE(m_vConnLineData.empty(), "OTableConnectionData::Init() : call only with empty line list!");
43 ResetConnLines();
44 // this creates the defaults
47 OTableConnectionData::OTableConnectionData( const OTableConnectionData& rConnData )
49 *this = rConnData;
52 void OTableConnectionData::CopyFrom(const OTableConnectionData& rSource)
54 *this = 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)
67 return *this;
69 m_pReferencingTable = rConnData.m_pReferencingTable;
70 m_pReferencedTable = rConnData.m_pReferencedTable;
71 m_aConnName = rConnData.m_aConnName;
73 // clear line list
74 ResetConnLines();
76 // and copy
77 for (auto const& elem : rConnData.GetConnLineDataList())
78 m_vConnLineData.push_back(new OConnectionLineData(*elem));
80 return *this;
83 void OTableConnectionData::SetConnLine( sal_uInt16 nIndex, const OUString& rSourceFieldName, const OUString& rDestFieldName )
85 if (sal_uInt16(m_vConnLineData.size()) < nIndex)
86 return;
88 // == still allowed, this corresponds to an Append
90 if (m_vConnLineData.size() == nIndex)
92 AppendConnLine(rSourceFieldName, rDestFieldName);
93 return;
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)
108 return true;
110 OConnectionLineDataRef pNew = new OConnectionLineData(rSourceFieldName, rDestFieldName);
111 if (!pNew.is())
112 return false;
114 m_vConnLineData.push_back(pNew);
115 return true;
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);
138 --nCount;
139 if (i < nRet)
140 nRet=i;
142 else
143 ++i;
145 return nRet;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */