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 "RTableConnection.hxx"
21 #include <RelationTableView.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <ConnectionLine.hxx>
25 
26 using namespace dbaui;
27 // class ORelationTableConnection
ORelationTableConnection(ORelationTableView * pContainer,const TTableConnectionData::value_type & pTabConnData)28 ORelationTableConnection::ORelationTableConnection( ORelationTableView* pContainer,
29                                                    const TTableConnectionData::value_type& pTabConnData )
30     :OTableConnection( pContainer, pTabConnData )
31 {
32 }
33 
ORelationTableConnection(const ORelationTableConnection & rConn)34 ORelationTableConnection::ORelationTableConnection( const ORelationTableConnection& rConn )
35     : VclReferenceBase(), OTableConnection( rConn )
36 {
37     // no own members, thus the base class functionality is enough
38 }
39 
operator =(const ORelationTableConnection & rConn)40 ORelationTableConnection& ORelationTableConnection::operator=( const ORelationTableConnection& rConn )
41 {
42     // this doesn't change anything, since the base class tests this, too and I don't have my own members to copy
43     if (&rConn == this)
44         return *this;
45 
46     OTableConnection::operator=( rConn );
47     return *this;
48 }
49 
Draw(vcl::RenderContext & rRenderContext,const tools::Rectangle & rRect)50 void ORelationTableConnection::Draw(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
51 {
52     OTableConnection::Draw(rRenderContext, rRect);
53     ORelationTableConnectionData* pData = static_cast< ORelationTableConnectionData* >(GetData().get());
54     if (pData && (pData->GetCardinality() == Cardinality::Undefined))
55         return;
56 
57     // search lines for top line
58     tools::Rectangle aBoundingRect;
59     long nTop = GetBoundingRect().Bottom();
60     long nTemp;
61 
62     const OConnectionLine* pTopLine = nullptr;
63     const std::vector<std::unique_ptr<OConnectionLine>>& rConnLineList = GetConnLineList();
64 
65     for (auto const& elem : rConnLineList)
66     {
67         if( elem->IsValid() )
68         {
69             aBoundingRect = elem->GetBoundingRect();
70             nTemp = aBoundingRect.Top();
71             if(nTemp < nTop)
72             {
73                 nTop = nTemp;
74                 pTopLine = elem.get();
75             }
76         }
77     }
78 
79     // cardinality
80     if (!pTopLine)
81         return;
82 
83     tools::Rectangle aSourcePos = pTopLine->GetSourceTextPos();
84     tools::Rectangle aDestPos = pTopLine->GetDestTextPos();
85 
86     OUString aSourceText;
87     OUString aDestText;
88 
89     switch (pData->GetCardinality())
90     {
91     case Cardinality::OneMany:
92         aSourceText = "1";
93         aDestText   = "n";
94         break;
95 
96     case Cardinality::ManyOne:
97         aSourceText = "n";
98         aDestText   = "1";
99         break;
100 
101     case Cardinality::OneOne:
102         aSourceText = "1";
103         aDestText   = "1";
104         break;
105     default: break;
106     }
107 
108     if (IsSelected())
109         rRenderContext.SetTextColor(Application::GetSettings().GetStyleSettings().GetHighlightColor());
110     else
111         rRenderContext.SetTextColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor());
112 
113     rRenderContext.DrawText(aSourcePos, aSourceText, DrawTextFlags::Clip | DrawTextFlags::Center | DrawTextFlags::Bottom);
114     rRenderContext.DrawText(aDestPos, aDestText, DrawTextFlags::Clip | DrawTextFlags::Center | DrawTextFlags::Bottom);
115 }
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
118