LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/querydesign - TableConnection.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 91 1.1 %
Date: 2013-07-09 Functions: 2 18 11.1 %
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             : 
      29             : using namespace dbaui;
      30             : using namespace comphelper;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::accessibility;
      33             : 
      34             : //========================================================================
      35             : // class OTableConnection
      36             : //========================================================================
      37             : namespace dbaui
      38             : {
      39             :     DBG_NAME(OTableConnection)
      40             :     //------------------------------------------------------------------------
      41           0 :     OTableConnection::OTableConnection( OJoinTableView* _pContainer,const TTableConnectionData::value_type& _pTabConnData )
      42             :         :Window(_pContainer)
      43             :         ,m_pData( _pTabConnData )
      44             :         ,m_pParent( _pContainer )
      45           0 :         ,m_bSelected( sal_False )
      46             :     {
      47             :         DBG_CTOR(OTableConnection,NULL);
      48           0 :         Init();
      49           0 :         Show();
      50           0 :     }
      51             : 
      52             :     //------------------------------------------------------------------------
      53           0 :     OTableConnection::OTableConnection( const OTableConnection& _rConn ) : Window(_rConn.m_pParent)
      54           0 :         ,m_pData(_rConn.GetData()->NewInstance())
      55             :     {
      56             :         DBG_CTOR(OTableConnection,NULL);
      57           0 :         *this = _rConn;
      58           0 :     }
      59             : 
      60             :     //------------------------------------------------------------------------
      61           0 :     void OTableConnection::Init()
      62             :     {
      63             :         //////////////////////////////////////////////////////////////////////
      64             :         // initialise linelist with defaults
      65           0 :         OConnectionLineDataVec* pLineData = GetData()->GetConnLineDataList();
      66           0 :         OConnectionLineDataVec::const_iterator aIter = pLineData->begin();
      67           0 :         OConnectionLineDataVec::const_iterator aEnd = pLineData->end();
      68           0 :         m_vConnLine.reserve(pLineData->size());
      69           0 :         for(;aIter != aEnd;++aIter)
      70           0 :             m_vConnLine.push_back( new OConnectionLine(this, *aIter) );
      71           0 :     }
      72             : 
      73             :     //------------------------------------------------------------------------
      74           0 :     OConnectionLine* OTableConnection::CreateConnLine( const OConnectionLine& rConnLine )
      75             :     {
      76           0 :         return new OConnectionLine( rConnLine );
      77             :     }
      78             :     // -----------------------------------------------------------------------------
      79           0 :     void OTableConnection::clearLineData()
      80             :     {
      81           0 :         ::std::vector<OConnectionLine*>::iterator aLineEnd = m_vConnLine.end();
      82           0 :         for(::std::vector<OConnectionLine*>::iterator aLineIter = m_vConnLine.begin();aLineIter != aLineEnd;++aLineIter)
      83           0 :             delete *aLineIter;
      84           0 :         m_vConnLine.clear();
      85           0 :     }
      86             :     //------------------------------------------------------------------------
      87           0 :     void OTableConnection::UpdateLineList()
      88             :     {
      89             :         //////////////////////////////////////////////////////////////////////
      90             :         // delete linelist
      91           0 :         clearLineData();
      92             : 
      93           0 :         Init();
      94           0 :     }
      95             : 
      96             :     //------------------------------------------------------------------------
      97           0 :     OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
      98             :     {
      99           0 :         if( &rConn == this )
     100           0 :             return *this;
     101             : 
     102             :         // delete linelist
     103           0 :         clearLineData();
     104             : 
     105             :         // copy linelist
     106           0 :         if(! rConn.GetConnLineList()->empty() )
     107             :         {
     108           0 :             const ::std::vector<OConnectionLine*>* pLine = rConn.GetConnLineList();
     109           0 :             ::std::vector<OConnectionLine*>::const_iterator aIter = pLine->begin();
     110           0 :             ::std::vector<OConnectionLine*>::const_iterator aEnd = pLine->end();
     111           0 :             m_vConnLine.reserve(pLine->size());
     112           0 :             for(;aIter != aEnd;++aIter)
     113           0 :                 m_vConnLine.push_back( CreateConnLine( **aIter ));
     114             :         }
     115             : 
     116             : 
     117             :         // as the data are not mine, I also do not delete the old
     118           0 :         m_pData->CopyFrom(*rConn.GetData());
     119             :         // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
     120             : 
     121           0 :         m_bSelected = rConn.m_bSelected;
     122           0 :         m_pParent = rConn.m_pParent;
     123             : 
     124           0 :         return *this;
     125             :     }
     126             : 
     127             : 
     128             :     //------------------------------------------------------------------------
     129           0 :     bool OTableConnection::RecalcLines()
     130             :     {
     131             :         // call RecalcLines on each line
     132           0 :         ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),::std::mem_fun(&OConnectionLine::RecalcLine));
     133           0 :         return true;
     134             :     }
     135             :     //------------------------------------------------------------------------
     136           0 :     OTableWindow* OTableConnection::GetSourceWin() const
     137             :     {
     138           0 :         TTableWindowData::value_type pRef = GetData()->getReferencingTable();
     139           0 :         OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
     140           0 :         if ( !pRet )
     141             :         {
     142           0 :             pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
     143             :         }
     144           0 :         return pRet;
     145             :     }
     146             :     //------------------------------------------------------------------------
     147           0 :     OTableWindow* OTableConnection::GetDestWin() const
     148             :     {
     149           0 :         TTableWindowData::value_type pRef = GetData()->getReferencedTable();
     150           0 :         OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
     151           0 :         if ( !pRet )
     152             :         {
     153           0 :             pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
     154             :         }
     155           0 :         return pRet;
     156             :     }
     157             : 
     158             :     //------------------------------------------------------------------------
     159           0 :     void OTableConnection::Select()
     160             :     {
     161           0 :         m_bSelected = sal_True;
     162           0 :         m_pParent->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN);
     163           0 :     }
     164             : 
     165             :     //------------------------------------------------------------------------
     166           0 :     void OTableConnection::Deselect()
     167             :     {
     168           0 :         m_bSelected = sal_False;
     169           0 :         InvalidateConnection();
     170           0 :     }
     171             : 
     172             :     //------------------------------------------------------------------------
     173           0 :     sal_Bool OTableConnection::CheckHit( const Point& rMousePos ) const
     174             :     {
     175             :         //////////////////////////////////////////////////////////////////////
     176             :         // check if the point hit our line
     177             :         ::std::vector<OConnectionLine*>::const_iterator aIter = ::std::find_if(m_vConnLine.begin(),
     178             :                                                                          m_vConnLine.end(),
     179           0 :                                                                          ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos));
     180           0 :         return aIter != m_vConnLine.end();
     181             :     }
     182             : 
     183             :     //------------------------------------------------------------------------
     184           0 :     bool OTableConnection::InvalidateConnection()
     185             :     {
     186           0 :         Rectangle rcBounding = GetBoundingRect();
     187           0 :         rcBounding.Bottom() += 1;
     188           0 :         rcBounding.Right() += 1;
     189             :         // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
     190             :         // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
     191             :         // Invalidate records obviously one pixel line less as Draw.
     192             :         // Or everything works differently .....  in any case it works ....
     193           0 :         m_pParent->Invalidate( rcBounding, INVALIDATE_NOCHILDREN );
     194             : 
     195           0 :         return true;
     196             :     }
     197             : 
     198             :     //------------------------------------------------------------------------
     199           0 :     Rectangle OTableConnection::GetBoundingRect() const
     200             :     {
     201             :         //////////////////////////////////////////////////////////////////////
     202             :         // determine all lines of the surrounding rectangle
     203           0 :         Rectangle aBoundingRect( Point(0,0), Point(0,0) );
     204           0 :         Rectangle aTempRect;
     205           0 :         ::std::vector<OConnectionLine*>::const_iterator aEnd = m_vConnLine.end();
     206           0 :         for(::std::vector<OConnectionLine*>::const_iterator aIter = m_vConnLine.begin();aIter != aEnd;++aIter)
     207             :         {
     208           0 :             aTempRect = (*aIter)->GetBoundingRect();
     209             : 
     210             :             //////////////////////////////////////////////////////////////////////
     211             :             // is the BoundingRect of this line valid?
     212           0 :             if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
     213             :             {
     214           0 :                 if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
     215           0 :                     aBoundingRect = aTempRect;
     216             :                 else
     217           0 :                     aBoundingRect.Union( aTempRect );
     218             :             }
     219             :         }
     220             : 
     221           0 :         return aBoundingRect;
     222             :     }
     223             : 
     224             :     //------------------------------------------------------------------------
     225           0 :     void OTableConnection::Draw( const Rectangle& /*rRect*/ )
     226             :     {
     227             :         //////////////////////////////////////////////////////////////////////
     228             :         // Draw line
     229           0 :         ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),TConnectionLineDrawFunctor(m_pParent));
     230           0 :     }
     231             :     // -----------------------------------------------------------------------------
     232          12 : }
     233             : 
     234             : 
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10