LibreOffice Module dbaccess (master) 1
TableConnection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <TableConnection.hxx>
21#include <ConnectionLine.hxx>
23#include <JoinTableView.hxx>
24#include <utility>
25
26using namespace dbaui;
27using namespace comphelper;
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::accessibility;
30
31namespace dbaui
32{
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 )
38 {
39 Init();
40 Show();
41 }
42
45 ,Window(_rConn.m_pParent.get())
46 ,m_pData(_rConn.GetData()->NewInstance())
47 ,m_pParent(nullptr)
48 {
49 *this = _rConn;
50 }
51
53 {
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) );
59 }
60
62 {
63 m_vConnLine.clear();
64 }
66 {
67 // delete linelist
69
70 Init();
71 }
72
74 {
75 if( &rConn == this )
76 return *this;
77
78 // delete linelist
80
81 // copy linelist
82 if(! rConn.GetConnLineList().empty() )
83 {
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));
88 }
89
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
93
95 m_pParent = rConn.m_pParent;
96
97 return *this;
98 }
99
101 {
102 // call RecalcLines on each line
103 for( const auto& pLine : m_vConnLine )
104 pLine->RecalcLine();
105 }
107 {
108 TTableWindowData::value_type pRef = GetData()->getReferencingTable();
109 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
110 if ( !pRet )
111 {
112 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
113 }
114 return pRet;
115 }
117 {
118 TTableWindowData::value_type pRef = GetData()->getReferencedTable();
119 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
120 if ( !pRet )
121 {
122 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
123 }
124 return pRet;
125 }
126
128 {
129 m_bSelected = true;
130 m_pParent->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren);
131 }
132
134 {
135 m_bSelected = false;
137 }
138
139 bool OTableConnection::CheckHit( const Point& rMousePos ) const
140 {
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 ); } );
147 }
148
150 {
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 );
159 }
160
162 {
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)
167 {
168 aTempRect = elem->GetBoundingRect();
169
170 // is the BoundingRect of this line valid?
171 if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
172 {
173 if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
174 aBoundingRect = aTempRect;
175 else
176 aBoundingRect.Union( aTempRect );
177 }
178 }
179
180 return aBoundingRect;
181 }
182
183 void OTableConnection::Draw(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
184 {
185 // Draw line
186 for( const auto& pLine : m_vConnLine )
187 pLine->Draw( &rRenderContext );
188 }
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::unique_ptr< OConnectionLine > > m_vConnLine
const TTableConnectionData::value_type & GetData() const
TTableConnectionData::value_type m_pData
OTableWindow * GetDestWin() const
OTableWindow * GetSourceWin() const
OTableConnection & operator=(const OTableConnection &rConn)
tools::Rectangle GetBoundingRect() const
void clearLineData()
loops through the vector and deletes all lines
VclPtr< OJoinTableView > m_pParent
const std::vector< std::unique_ptr< OConnectionLine > > & GetConnLineList() const
bool CheckHit(const Point &rMousePos) const
OTableConnection(OJoinTableView *pContainer, TTableConnectionData::value_type aTabConnData)
virtual void Draw(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
constexpr tools::Long GetWidth() const
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
constexpr tools::Long GetHeight() const
tools::Rectangle & Union(const tools::Rectangle &rRect)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
ControllerFrame_Data * m_pData
std::vector< OConnectionLineDataRef > OConnectionLineDataVec
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)