LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - TableConnection.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 90 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      22             : #include "TableConnectionData.hxx"
      23             : #include "JoinTableView.hxx"
      24             : #include <comphelper/stl_types.hxx>
      25             : #include "ConnectionLineAccess.hxx"
      26             : #include <algorithm>
      27             : 
      28             : using namespace dbaui;
      29             : using namespace comphelper;
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::accessibility;
      32             : 
      33             : // class OTableConnection
      34             : namespace dbaui
      35             : {
      36           0 :     OTableConnection::OTableConnection( OJoinTableView* _pContainer,const TTableConnectionData::value_type& _pTabConnData )
      37             :         :Window(_pContainer)
      38             :         ,m_pData( _pTabConnData )
      39             :         ,m_pParent( _pContainer )
      40           0 :         ,m_bSelected( false )
      41             :     {
      42           0 :         Init();
      43           0 :         Show();
      44           0 :     }
      45             : 
      46           0 :     OTableConnection::OTableConnection( const OTableConnection& _rConn ) : Window(_rConn.m_pParent.get())
      47           0 :         ,m_pData(_rConn.GetData()->NewInstance())
      48           0 :         ,m_pParent(NULL)
      49             :     {
      50           0 :         *this = _rConn;
      51           0 :     }
      52             : 
      53           0 :     void OTableConnection::Init()
      54             :     {
      55             :         // initialise linelist with defaults
      56           0 :         OConnectionLineDataVec& rLineData = GetData()->GetConnLineDataList();
      57           0 :         OConnectionLineDataVec::const_iterator aIter = rLineData.begin();
      58           0 :         OConnectionLineDataVec::const_iterator aEnd = rLineData.end();
      59           0 :         m_vConnLine.reserve(rLineData.size());
      60           0 :         for(;aIter != aEnd;++aIter)
      61           0 :             m_vConnLine.push_back( new OConnectionLine(this, *aIter) );
      62           0 :     }
      63             : 
      64           0 :     OConnectionLine* OTableConnection::CreateConnLine( const OConnectionLine& rConnLine )
      65             :     {
      66           0 :         return new OConnectionLine( rConnLine );
      67             :     }
      68           0 :     void OTableConnection::clearLineData()
      69             :     {
      70           0 :         ::std::vector<OConnectionLine*>::iterator aLineEnd = m_vConnLine.end();
      71           0 :         for(::std::vector<OConnectionLine*>::iterator aLineIter = m_vConnLine.begin();aLineIter != aLineEnd;++aLineIter)
      72           0 :             delete *aLineIter;
      73           0 :         m_vConnLine.clear();
      74           0 :     }
      75           0 :     void OTableConnection::UpdateLineList()
      76             :     {
      77             :         // delete linelist
      78           0 :         clearLineData();
      79             : 
      80           0 :         Init();
      81           0 :     }
      82             : 
      83           0 :     OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
      84             :     {
      85           0 :         if( &rConn == this )
      86           0 :             return *this;
      87             : 
      88             :         // delete linelist
      89           0 :         clearLineData();
      90             : 
      91             :         // copy linelist
      92           0 :         if(! rConn.GetConnLineList().empty() )
      93             :         {
      94           0 :             const ::std::vector<OConnectionLine*>& rLine = rConn.GetConnLineList();
      95           0 :             ::std::vector<OConnectionLine*>::const_iterator aIter = rLine.begin();
      96           0 :             ::std::vector<OConnectionLine*>::const_iterator aEnd = rLine.end();
      97           0 :             m_vConnLine.reserve(rLine.size());
      98           0 :             for(;aIter != aEnd;++aIter)
      99           0 :                 m_vConnLine.push_back( CreateConnLine( **aIter ));
     100             :         }
     101             : 
     102             :         // as the data are not mine, I also do not delete the old
     103           0 :         m_pData->CopyFrom(*rConn.GetData());
     104             :         // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
     105             : 
     106           0 :         m_bSelected = rConn.m_bSelected;
     107           0 :         m_pParent = rConn.m_pParent;
     108             : 
     109           0 :         return *this;
     110             :     }
     111             : 
     112           0 :     bool OTableConnection::RecalcLines()
     113             :     {
     114             :         // call RecalcLines on each line
     115           0 :         ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),::std::mem_fun(&OConnectionLine::RecalcLine));
     116           0 :         return true;
     117             :     }
     118           0 :     OTableWindow* OTableConnection::GetSourceWin() const
     119             :     {
     120           0 :         TTableWindowData::value_type pRef = GetData()->getReferencingTable();
     121           0 :         OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
     122           0 :         if ( !pRet )
     123             :         {
     124           0 :             pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
     125             :         }
     126           0 :         return pRet;
     127             :     }
     128           0 :     OTableWindow* OTableConnection::GetDestWin() const
     129             :     {
     130           0 :         TTableWindowData::value_type pRef = GetData()->getReferencedTable();
     131           0 :         OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
     132           0 :         if ( !pRet )
     133             :         {
     134           0 :             pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
     135             :         }
     136           0 :         return pRet;
     137             :     }
     138             : 
     139           0 :     void OTableConnection::Select()
     140             :     {
     141           0 :         m_bSelected = true;
     142           0 :         m_pParent->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren);
     143           0 :     }
     144             : 
     145           0 :     void OTableConnection::Deselect()
     146             :     {
     147           0 :         m_bSelected = false;
     148           0 :         InvalidateConnection();
     149           0 :     }
     150             : 
     151           0 :     bool OTableConnection::CheckHit( const Point& rMousePos ) const
     152             :     {
     153             :         // check if the point hit our line
     154             :         return ::std::any_of(m_vConnLine.begin(),
     155             :                              m_vConnLine.end(),
     156           0 :                              ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos));
     157             :     }
     158             : 
     159           0 :     bool OTableConnection::InvalidateConnection()
     160             :     {
     161           0 :         Rectangle rcBounding = GetBoundingRect();
     162           0 :         rcBounding.Bottom() += 1;
     163           0 :         rcBounding.Right() += 1;
     164             :         // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
     165             :         // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
     166             :         // Invalidate records obviously one pixel line less as Draw.
     167             :         // Or everything works differently .....  in any case it works ....
     168           0 :         m_pParent->Invalidate( rcBounding, InvalidateFlags::NoChildren );
     169             : 
     170           0 :         return true;
     171             :     }
     172             : 
     173           0 :     Rectangle OTableConnection::GetBoundingRect() const
     174             :     {
     175             :         // determine all lines of the surrounding rectangle
     176           0 :         Rectangle aBoundingRect( Point(0,0), Point(0,0) );
     177           0 :         Rectangle aTempRect;
     178           0 :         ::std::vector<OConnectionLine*>::const_iterator aEnd = m_vConnLine.end();
     179           0 :         for(::std::vector<OConnectionLine*>::const_iterator aIter = m_vConnLine.begin();aIter != aEnd;++aIter)
     180             :         {
     181           0 :             aTempRect = (*aIter)->GetBoundingRect();
     182             : 
     183             :             // is the BoundingRect of this line valid?
     184           0 :             if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
     185             :             {
     186           0 :                 if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
     187           0 :                     aBoundingRect = aTempRect;
     188             :                 else
     189           0 :                     aBoundingRect.Union( aTempRect );
     190             :             }
     191             :         }
     192             : 
     193           0 :         return aBoundingRect;
     194             :     }
     195             : 
     196           0 :     void OTableConnection::Draw(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
     197             :     {
     198             :         // Draw line
     199           0 :         std::for_each(m_vConnLine.begin(), m_vConnLine.end(), TConnectionLineDrawFunctor(&rRenderContext));
     200           0 :     }
     201             : }
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11