Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableConnection.cxx
blob1e9d31f419c0b8cf26dd89ac731cb18869df2482
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 <TableConnection.hxx>
21 #include <ConnectionLine.hxx>
22 #include <TableConnectionData.hxx>
23 #include <JoinTableView.hxx>
24 #include <utility>
26 using namespace dbaui;
27 using namespace ::com::sun::star::accessibility;
29 namespace dbaui
31 OTableConnection::OTableConnection( OJoinTableView* _pContainer, TTableConnectionData::value_type _aTabConnData )
32 :Window(_pContainer)
33 ,m_pData(std::move( _aTabConnData ))
34 ,m_pParent( _pContainer )
35 ,m_bSelected( false )
37 Init();
38 Show();
41 OTableConnection::OTableConnection( const OTableConnection& _rConn )
42 : VclReferenceBase()
43 ,Window(_rConn.m_pParent.get())
44 ,m_pData(_rConn.GetData()->NewInstance())
45 ,m_pParent(nullptr)
47 *this = _rConn;
50 void OTableConnection::Init()
52 // initialise linelist with defaults
53 OConnectionLineDataVec& rLineData = GetData()->GetConnLineDataList();
54 m_vConnLine.reserve(rLineData.size());
55 for (auto const& elem : rLineData)
56 m_vConnLine.emplace_back( new OConnectionLine(this, elem) );
59 void OTableConnection::clearLineData()
61 m_vConnLine.clear();
63 void OTableConnection::UpdateLineList()
65 // delete linelist
66 clearLineData();
68 Init();
71 OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
73 if( &rConn == this )
74 return *this;
76 // delete linelist
77 clearLineData();
79 // copy linelist
80 if(! rConn.GetConnLineList().empty() )
82 const std::vector<std::unique_ptr<OConnectionLine>>& rLine = rConn.GetConnLineList();
83 m_vConnLine.reserve(rLine.size());
84 for (auto const& elem : rLine)
85 m_vConnLine.emplace_back( new OConnectionLine(*elem));
88 // as the data are not mine, I also do not delete the old
89 m_pData->CopyFrom(*rConn.GetData());
90 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
92 m_bSelected = rConn.m_bSelected;
93 m_pParent = rConn.m_pParent;
95 return *this;
98 void OTableConnection::RecalcLines()
100 // call RecalcLines on each line
101 for( const auto& pLine : m_vConnLine )
102 pLine->RecalcLine();
104 OTableWindow* OTableConnection::GetSourceWin() const
106 TTableWindowData::value_type pRef = GetData()->getReferencingTable();
107 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
108 if ( !pRet )
110 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
112 return pRet;
114 OTableWindow* OTableConnection::GetDestWin() const
116 TTableWindowData::value_type pRef = GetData()->getReferencedTable();
117 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
118 if ( !pRet )
120 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
122 return pRet;
125 void OTableConnection::Select()
127 m_bSelected = true;
128 m_pParent->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren);
131 void OTableConnection::Deselect()
133 m_bSelected = false;
134 InvalidateConnection();
137 bool OTableConnection::CheckHit( const Point& rMousePos ) const
139 // check if the point hit our line
140 return std::any_of(m_vConnLine.begin(),
141 m_vConnLine.end(),
142 [&rMousePos]
143 ( const std::unique_ptr<OConnectionLine> & pLine )
144 { return pLine->CheckHit( rMousePos ); } );
147 void OTableConnection::InvalidateConnection()
149 tools::Rectangle rcBounding = GetBoundingRect();
150 rcBounding.AdjustBottom(1 );
151 rcBounding.AdjustRight(1 );
152 // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
153 // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
154 // Invalidate records obviously one pixel line less as Draw.
155 // Or everything works differently... in any case it works...
156 m_pParent->Invalidate( rcBounding, InvalidateFlags::NoChildren );
159 tools::Rectangle OTableConnection::GetBoundingRect() const
161 // determine all lines of the surrounding rectangle
162 tools::Rectangle aBoundingRect( Point(0,0), Point(0,0) );
163 tools::Rectangle aTempRect;
164 for (auto const& elem : m_vConnLine)
166 aTempRect = elem->GetBoundingRect();
168 // is the BoundingRect of this line valid?
169 if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
171 if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
172 aBoundingRect = aTempRect;
173 else
174 aBoundingRect.Union( aTempRect );
178 return aBoundingRect;
181 void OTableConnection::Draw(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
183 // Draw line
184 for( const auto& pLine : m_vConnLine )
185 pLine->Draw( &rRenderContext );
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */