android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableConnection.cxx
blob2bfceb1b6c6928bd1ac95b55c4fa32e07d73558b
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 comphelper;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::accessibility;
31 namespace dbaui
33 OTableConnection::OTableConnection( OJoinTableView* _pContainer, TTableConnectionData::value_type _aTabConnData )
34 :Window(_pContainer)
35 ,m_pData(std::move( _aTabConnData ))
36 ,m_pParent( _pContainer )
37 ,m_bSelected( false )
39 Init();
40 Show();
43 OTableConnection::OTableConnection( const OTableConnection& _rConn )
44 : VclReferenceBase()
45 ,Window(_rConn.m_pParent.get())
46 ,m_pData(_rConn.GetData()->NewInstance())
47 ,m_pParent(nullptr)
49 *this = _rConn;
52 void OTableConnection::Init()
54 // initialise linelist with defaults
55 OConnectionLineDataVec& rLineData = GetData()->GetConnLineDataList();
56 m_vConnLine.reserve(rLineData.size());
57 for (auto const& elem : rLineData)
58 m_vConnLine.emplace_back( new OConnectionLine(this, elem) );
61 void OTableConnection::clearLineData()
63 m_vConnLine.clear();
65 void OTableConnection::UpdateLineList()
67 // delete linelist
68 clearLineData();
70 Init();
73 OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
75 if( &rConn == this )
76 return *this;
78 // delete linelist
79 clearLineData();
81 // copy linelist
82 if(! rConn.GetConnLineList().empty() )
84 const std::vector<std::unique_ptr<OConnectionLine>>& rLine = rConn.GetConnLineList();
85 m_vConnLine.reserve(rLine.size());
86 for (auto const& elem : rLine)
87 m_vConnLine.emplace_back( new OConnectionLine(*elem));
90 // as the data are not mine, I also do not delete the old
91 m_pData->CopyFrom(*rConn.GetData());
92 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
94 m_bSelected = rConn.m_bSelected;
95 m_pParent = rConn.m_pParent;
97 return *this;
100 void OTableConnection::RecalcLines()
102 // call RecalcLines on each line
103 for( const auto& pLine : m_vConnLine )
104 pLine->RecalcLine();
106 OTableWindow* OTableConnection::GetSourceWin() const
108 TTableWindowData::value_type pRef = GetData()->getReferencingTable();
109 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
110 if ( !pRet )
112 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
114 return pRet;
116 OTableWindow* OTableConnection::GetDestWin() const
118 TTableWindowData::value_type pRef = GetData()->getReferencedTable();
119 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
120 if ( !pRet )
122 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
124 return pRet;
127 void OTableConnection::Select()
129 m_bSelected = true;
130 m_pParent->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren);
133 void OTableConnection::Deselect()
135 m_bSelected = false;
136 InvalidateConnection();
139 bool OTableConnection::CheckHit( const Point& rMousePos ) const
141 // check if the point hit our line
142 return std::any_of(m_vConnLine.begin(),
143 m_vConnLine.end(),
144 [&rMousePos]
145 ( const std::unique_ptr<OConnectionLine> & pLine )
146 { return pLine->CheckHit( rMousePos ); } );
149 void OTableConnection::InvalidateConnection()
151 tools::Rectangle rcBounding = GetBoundingRect();
152 rcBounding.AdjustBottom(1 );
153 rcBounding.AdjustRight(1 );
154 // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
155 // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
156 // Invalidate records obviously one pixel line less as Draw.
157 // Or everything works differently... in any case it works...
158 m_pParent->Invalidate( rcBounding, InvalidateFlags::NoChildren );
161 tools::Rectangle OTableConnection::GetBoundingRect() const
163 // determine all lines of the surrounding rectangle
164 tools::Rectangle aBoundingRect( Point(0,0), Point(0,0) );
165 tools::Rectangle aTempRect;
166 for (auto const& elem : m_vConnLine)
168 aTempRect = elem->GetBoundingRect();
170 // is the BoundingRect of this line valid?
171 if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
173 if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
174 aBoundingRect = aTempRect;
175 else
176 aBoundingRect.Union( aTempRect );
180 return aBoundingRect;
183 void OTableConnection::Draw(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
185 // Draw line
186 for( const auto& pLine : m_vConnLine )
187 pLine->Draw( &rRenderContext );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */