// Copyright (c) 2014-2021 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include #include namespace xlnt { /// /// Enumeration of possible types of sheet views /// enum class sheet_view_type { normal, page_break_preview, page_layout }; /// /// Describes a view of a worksheet. /// Worksheets can have multiple views which show the data differently. /// class XLNT_API sheet_view { public: /// /// Sets the ID of this view to new_id. /// void id(std::size_t new_id) { id_ = new_id; } /// /// Returns the ID of this view. /// std::size_t id() const { return id_; } /// /// Returns true if this view has a pane defined. /// bool has_pane() const { return pane_.is_set(); } /// /// Returns a reference to this view's pane. /// struct pane &pane() { return pane_.get(); } /// /// Returns a reference to this view's pane. /// const struct pane &pane() const { return pane_.get(); } /// /// Removes the defined pane from this view. /// void clear_pane() { pane_.clear(); } /// /// Sets the pane of this view to new_pane. /// void pane(const struct pane &new_pane) { pane_ = new_pane; } /// /// Returns true if this view has any selections. /// bool has_selections() const { return !selections_.empty(); } /// /// Adds the given selection to the collection of selections. /// void add_selection(const class selection &new_selection) { selections_.push_back(new_selection); } /// /// Removes all selections. /// void clear_selections() { selections_.clear(); } /// /// Returns the collection of selections as a vector. /// std::vector selections() const { return selections_; } /// /// Returns the selection at the given index. /// class xlnt::selection &selection(std::size_t index) { return selections_.at(index); } /// /// If show is true, grid lines will be shown for sheets using this view. /// void show_grid_lines(bool show) { show_grid_lines_ = show; } /// /// Returns true if grid lines will be shown for sheets using this view. /// bool show_grid_lines() const { return show_grid_lines_; } /// /// If is_default is true, the default grid color will be used. /// void default_grid_color(bool is_default) { default_grid_color_ = is_default; } /// /// Returns true if the default grid color will be used. /// bool default_grid_color() const { return default_grid_color_; } /// /// Sets the type of this view. /// void type(sheet_view_type new_type) { type_ = new_type; } /// /// Returns the type of this view. /// sheet_view_type type() const { return type_; } /// /// has a top left cell? /// bool has_top_left_cell() const { return top_left_cell_.is_set(); } /// /// Sets the top left cell of this view. /// void top_left_cell(const cell_reference &ref) { top_left_cell_.set(ref); } /// /// Returns the top left cell of this view. /// cell_reference top_left_cell() const { return top_left_cell_.get(); } /// /// Returns true if this view is equal to rhs based on its id, grid lines setting, /// default grid color, pane, and selections. /// bool operator==(const sheet_view &rhs) const { return id_ == rhs.id_ && show_grid_lines_ == rhs.show_grid_lines_ && default_grid_color_ == rhs.default_grid_color_ && pane_ == rhs.pane_ && selections_ == rhs.selections_ && top_left_cell_ == rhs.top_left_cell_; } private: /// /// The id /// std::size_t id_ = 0; /// /// Whether or not to show grid lines /// bool show_grid_lines_ = true; /// /// Whether or not to use the default grid color /// bool default_grid_color_ = true; /// /// The type of this view /// sheet_view_type type_ = sheet_view_type::normal; /// /// The optional pane /// optional pane_; /// /// The top left cell /// optional top_left_cell_; /// /// The collection of selections /// std::vector selections_; }; } // namespace xlnt