differential code coverage report with master
Current view: top level - include/xlnt/worksheet - sheet_view.hpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 100.0 % 62 62 62
Current Date: 2025-12-07 02:01:22 Functions: 100.0 % 23 23 23
Baseline: coverage_master.info Branches: 50.0 % 14 7 14 14
Baseline Date: 2025-12-07 02:01:21

             Branch data    TLA  Line data    Source code
       1                 :                : // Copyright (c) 2014-2022 Thomas Fussell
       2                 :                : // Copyright (c) 2010-2015 openpyxl
       3                 :                : // Copyright (c) 2024-2025 xlnt-community
       4                 :                : //
       5                 :                : // Permission is hereby granted, free of charge, to any person obtaining a copy
       6                 :                : // of this software and associated documentation files (the "Software"), to deal
       7                 :                : // in the Software without restriction, including without limitation the rights
       8                 :                : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9                 :                : // copies of the Software, and to permit persons to whom the Software is
      10                 :                : // furnished to do so, subject to the following conditions:
      11                 :                : //
      12                 :                : // The above copyright notice and this permission notice shall be included in
      13                 :                : // all copies or substantial portions of the Software.
      14                 :                : //
      15                 :                : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16                 :                : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17                 :                : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18                 :                : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19                 :                : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20                 :                : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21                 :                : // THE SOFTWARE
      22                 :                : //
      23                 :                : // @license: http://www.opensource.org/licenses/mit-license.php
      24                 :                : // @author: see AUTHORS file
      25                 :                : 
      26                 :                : #pragma once
      27                 :                : 
      28                 :                : #include <xlnt/xlnt_config.hpp>
      29                 :                : #include <xlnt/utils/optional.hpp>
      30                 :                : #include <xlnt/worksheet/pane.hpp>
      31                 :                : #include <xlnt/worksheet/selection.hpp>
      32                 :                : 
      33                 :                : namespace xlnt {
      34                 :                : 
      35                 :                : /// <summary>
      36                 :                : /// Enumeration of possible types of sheet views
      37                 :                : /// </summary>
      38                 :                : enum class sheet_view_type
      39                 :                : {
      40                 :                :     normal,
      41                 :                :     page_break_preview,
      42                 :                :     page_layout
      43                 :                : };
      44                 :                : 
      45                 :                : /// <summary>
      46                 :                : /// Describes a view of a worksheet.
      47                 :                : /// Worksheets can have multiple views which show the data differently.
      48                 :                : /// </summary>
      49                 :                : class XLNT_API sheet_view
      50                 :                : {
      51                 :                : public:
      52                 :                :     /// <summary>
      53                 :                :     /// Sets the ID of this view to new_id.
      54                 :                :     /// </summary>
      55                 :CBC         116 :     void id(std::size_t new_id)
      56                 :                :     {
      57                 :            116 :         id_ = new_id;
      58                 :            116 :     }
      59                 :                : 
      60                 :                :     /// <summary>
      61                 :                :     /// Returns the ID of this view.
      62                 :                :     /// </summary>
      63                 :             50 :     std::size_t id() const
      64                 :                :     {
      65                 :             50 :         return id_;
      66                 :                :     }
      67                 :                : 
      68                 :                :     /// <summary>
      69                 :                :     /// Returns true if this view has a pane defined.
      70                 :                :     /// </summary>
      71                 :             60 :     bool has_pane() const
      72                 :                :     {
      73                 :             60 :         return pane_.is_set();
      74                 :                :     }
      75                 :                : 
      76                 :                :     /// <summary>
      77                 :                :     /// Returns a reference to this view's pane.
      78                 :                :     /// </summary>
      79                 :             45 :     struct pane &pane()
      80                 :                :     {
      81                 :             45 :         return pane_.get();
      82                 :                :     }
      83                 :                : 
      84                 :                :     /// <summary>
      85                 :                :     /// Returns a reference to this view's pane.
      86                 :                :     /// </summary>
      87                 :              2 :     const struct pane &pane() const
      88                 :                :     {
      89                 :              2 :         return pane_.get();
      90                 :                :     }
      91                 :                : 
      92                 :                :     /// <summary>
      93                 :                :     /// Removes the defined pane from this view.
      94                 :                :     /// </summary>
      95                 :              2 :     void clear_pane()
      96                 :                :     {
      97                 :              2 :         pane_.clear();
      98                 :              2 :     }
      99                 :                : 
     100                 :                :     /// <summary>
     101                 :                :     /// Sets the pane of this view to new_pane.
     102                 :                :     /// </summary>
     103                 :              9 :     void pane(const struct pane &new_pane)
     104                 :                :     {
     105                 :              9 :         pane_ = new_pane;
     106                 :              9 :     }
     107                 :                : 
     108                 :                :     /// <summary>
     109                 :                :     /// Returns true if this view has any selections.
     110                 :                :     /// </summary>
     111                 :              7 :     bool has_selections() const
     112                 :                :     {
     113                 :              7 :         return !selections_.empty();
     114                 :                :     }
     115                 :                : 
     116                 :                :     /// <summary>
     117                 :                :     /// Adds the given selection to the collection of selections.
     118                 :                :     /// </summary>
     119                 :             90 :     void add_selection(const class selection &new_selection)
     120                 :                :     {
     121                 :             90 :         selections_.push_back(new_selection);
     122                 :             90 :     }
     123                 :                : 
     124                 :                :     /// <summary>
     125                 :                :     /// Removes all selections.
     126                 :                :     /// </summary>
     127                 :              8 :     void clear_selections()
     128                 :                :     {
     129                 :              8 :         selections_.clear();
     130                 :              8 :     }
     131                 :                : 
     132                 :                :     /// <summary>
     133                 :                :     /// Returns the collection of selections as a vector.
     134                 :                :     /// </summary>
     135                 :             69 :     std::vector<xlnt::selection> selections() const
     136                 :                :     {
     137                 :             69 :         return selections_;
     138                 :                :     }
     139                 :                : 
     140                 :                :     /// <summary>
     141                 :                :     /// Returns the selection at the given index.
     142                 :                :     /// </summary>
     143                 :             11 :     class xlnt::selection &selection(std::size_t index)
     144                 :                :     {
     145                 :             11 :         return selections_.at(index);
     146                 :                :     }
     147                 :                : 
     148                 :                :     /// <summary>
     149                 :                :     /// If show is true, grid lines will be shown for sheets using this view.
     150                 :                :     /// </summary>
     151                 :             24 :     void show_grid_lines(bool show)
     152                 :                :     {
     153                 :             24 :         show_grid_lines_ = show;
     154                 :             24 :     }
     155                 :                : 
     156                 :                :     /// <summary>
     157                 :                :     /// Returns true if grid lines will be shown for sheets using this view.
     158                 :                :     /// </summary>
     159                 :             51 :     bool show_grid_lines() const
     160                 :                :     {
     161                 :             51 :         return show_grid_lines_;
     162                 :                :     }
     163                 :                : 
     164                 :                :     /// <summary>
     165                 :                :     /// If is_default is true, the default grid color will be used.
     166                 :                :     /// </summary>
     167                 :             21 :     void default_grid_color(bool is_default)
     168                 :                :     {
     169                 :             21 :         default_grid_color_ = is_default;
     170                 :             21 :     }
     171                 :                : 
     172                 :                :     /// <summary>
     173                 :                :     /// Returns true if the default grid color will be used.
     174                 :                :     /// </summary>
     175                 :                :     bool default_grid_color() const
     176                 :                :     {
     177                 :                :         return default_grid_color_;
     178                 :                :     }
     179                 :                : 
     180                 :                :     /// <summary>
     181                 :                :     /// Sets the type of this view.
     182                 :                :     /// </summary>
     183                 :              4 :     void type(sheet_view_type new_type)
     184                 :                :     {
     185                 :              4 :         type_ = new_type;
     186                 :              4 :     }
     187                 :                : 
     188                 :                :     /// <summary>
     189                 :                :     /// Returns the type of this view.
     190                 :                :     /// </summary>
     191                 :             52 :     sheet_view_type type() const
     192                 :                :     {
     193                 :             52 :         return type_;
     194                 :                :     }
     195                 :                : 
     196                 :                :     /// <summary>
     197                 :                :     /// has a  top left cell?
     198                 :                :     /// </summary>
     199                 :             50 :     bool has_top_left_cell() const
     200                 :                :     {
     201                 :             50 :         return top_left_cell_.is_set();
     202                 :                :     }
     203                 :                : 
     204                 :                :     /// <summary>
     205                 :                :     /// Sets the top left cell of this view.
     206                 :                :     /// </summary>
     207                 :             23 :     void top_left_cell(const cell_reference &ref)
     208                 :                :     {
     209                 :             23 :         top_left_cell_.set(ref);
     210                 :             23 :     }
     211                 :                : 
     212                 :                :     /// <summary>
     213                 :                :     /// Returns the top left cell of this view.
     214                 :                :     /// </summary>
     215                 :              3 :     cell_reference top_left_cell() const
     216                 :                :     {
     217                 :              3 :         return top_left_cell_.get();
     218                 :                :     }
     219                 :                : 
     220                 :                :     /// <summary>
     221                 :                :     /// Sets the zoom scale (percentage) for this view.
     222                 :                :     /// </summary>
     223                 :             22 :     void zoom_scale(int scale)
     224                 :                :     {
     225                 :             22 :         zoom_scale_ = scale;
     226                 :             22 :     }
     227                 :                : 
     228                 :                :     /// <summary>
     229                 :                :     /// Returns the zoom scale (percentage).
     230                 :                :     /// </summary>
     231                 :             56 :     int zoom_scale() const
     232                 :                :     {
     233                 :             56 :         return zoom_scale_;
     234                 :                :     }
     235                 :                : 
     236                 :                :     /// <summary>
     237                 :                :     /// Returns true if this view is equal to rhs based on its id, grid lines setting,
     238                 :                :     /// default grid color, pane, and selections.
     239                 :                :     /// </summary>
     240                 :              8 :     bool operator==(const sheet_view &rhs) const
     241                 :                :     {
     242                 :              8 :         return id_ == rhs.id_
     243         [ +  - ]:              8 :             && show_grid_lines_ == rhs.show_grid_lines_
     244         [ +  - ]:              8 :             && default_grid_color_ == rhs.default_grid_color_
     245         [ +  - ]:              8 :             && pane_ == rhs.pane_
     246         [ +  - ]:              8 :             && selections_ == rhs.selections_
     247         [ +  - ]:              8 :             && top_left_cell_ == rhs.top_left_cell_
     248   [ +  -  +  - ]:             16 :             && zoom_scale_ == rhs.zoom_scale_;
     249                 :                :     }
     250                 :                : 
     251                 :                :     /// <summary>
     252                 :                :     /// Returns the negation of the equality operator.
     253                 :                :     /// </summary>
     254                 :                :     bool operator!=(const sheet_view &rhs) const
     255                 :                :     {
     256                 :                :         return !(*this == rhs);
     257                 :                :     }
     258                 :                : 
     259                 :                : private:
     260                 :                :     /// <summary>
     261                 :                :     /// The id
     262                 :                :     /// </summary>
     263                 :                :     std::size_t id_ = 0;
     264                 :                : 
     265                 :                :     /// <summary>
     266                 :                :     /// Whether or not to show grid lines
     267                 :                :     /// </summary>
     268                 :                :     bool show_grid_lines_ = true;
     269                 :                : 
     270                 :                :     /// <summary>
     271                 :                :     /// Whether or not to use the default grid color
     272                 :                :     /// </summary>
     273                 :                :     bool default_grid_color_ = true;
     274                 :                : 
     275                 :                :     /// <summary>
     276                 :                :     /// The type of this view
     277                 :                :     /// </summary>
     278                 :                :     sheet_view_type type_ = sheet_view_type::normal;
     279                 :                : 
     280                 :                :     /// <summary>
     281                 :                :     /// The optional pane
     282                 :                :     /// </summary>
     283                 :                :     optional<xlnt::pane> pane_;
     284                 :                : 
     285                 :                :     /// <summary>
     286                 :                :     /// The top left cell
     287                 :                :     /// </summary>
     288                 :                :     optional<cell_reference> top_left_cell_;
     289                 :                : 
     290                 :                :     /// <summary>
     291                 :                :     /// The collection of selections
     292                 :                :     /// </summary>
     293                 :                :     std::vector<xlnt::selection> selections_;
     294                 :                : 
     295                 :                :     /// <summary>
     296                 :                :     /// The zoom scale (percent), e.g. 100
     297                 :                :     /// </summary>
     298                 :                :     int zoom_scale_ = 100;
     299                 :                : };
     300                 :                : 
     301                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta