File indexing completed on 2024-05-12 15:26:38

0001 /***************************************************************************
0002     File                 : abstractcolumncommands.cpp
0003     Project              : LabPlot
0004     Description          : Commands to be called by AbstractColumn to modify AbstractColumnPrivate
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2007-2009 Tilman Benkert (thzs@gmx.net)
0007     Copyright            : (C) 2010 Knut Franke (knut.franke@gmx.de)
0008 
0009  ***************************************************************************/
0010 
0011 /***************************************************************************
0012  *                                                                         *
0013  *  This program is free software; you can redistribute it and/or modify   *
0014  *  it under the terms of the GNU General Public License as published by   *
0015  *  the Free Software Foundation; either version 2 of the License, or      *
0016  *  (at your option) any later version.                                    *
0017  *                                                                         *
0018  *  This program is distributed in the hope that it will be useful,        *
0019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0021  *  GNU General Public License for more details.                           *
0022  *                                                                         *
0023  *   You should have received a copy of the GNU General Public License     *
0024  *   along with this program; if not, write to the Free Software           *
0025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0026  *   Boston, MA  02110-1301  USA                                           *
0027  *                                                                         *
0028  ***************************************************************************/
0029 
0030 #include "abstractcolumncommands.h"
0031 #include <KLocalizedString>
0032 
0033 /** ***************************************************************************
0034  * \class AbstractColumnClearMasksCmd
0035  * \brief Clear masking information
0036  ** ***************************************************************************/
0037 
0038 /**
0039  * \var AbstractColumnClearMasksCmd::m_col
0040  * \brief The private column data to modify
0041  */
0042 
0043 /**
0044  * \var AbstractColumnClearMasksCmd::m_masking
0045  * \brief The old masks
0046  */
0047 
0048 /**
0049  * \var AbstractColumnClearMasksCmd::m_copied
0050  * \brief A status flag
0051  */
0052 
0053 /**
0054  * \brief Ctor
0055  */
0056 AbstractColumnClearMasksCmd::AbstractColumnClearMasksCmd(AbstractColumnPrivate* col, QUndoCommand* parent)
0057 : QUndoCommand( parent ), m_col(col) {
0058     setText(i18n("%1: clear masks", col->name()));
0059     m_copied = false;
0060 }
0061 
0062 /**
0063  * \brief Dtor
0064  */
0065 AbstractColumnClearMasksCmd::~AbstractColumnClearMasksCmd()
0066 = default;
0067 
0068 /**
0069  * \brief Execute the command
0070  */
0071 void AbstractColumnClearMasksCmd::redo() {
0072     if (!m_copied) {
0073         m_masking = m_col->m_masking;
0074         m_copied = true;
0075     }
0076     m_col->m_masking.clear();
0077     emit m_col->owner()->dataChanged(m_col->owner());
0078 }
0079 
0080 /**
0081  * \brief Undo the command
0082  */
0083 void AbstractColumnClearMasksCmd::undo() {
0084     m_col->m_masking = m_masking;
0085     emit m_col->owner()->dataChanged(m_col->owner());
0086 }
0087 
0088 /** ***************************************************************************
0089  * \class AbstractColumnSetMaskedCmd
0090  * \brief Mark an interval of rows as masked
0091  ** ***************************************************************************/
0092 
0093 /**
0094  * \var AbstractColumnSetMaskedCmd::m_col
0095  * \brief The private AbstractColumn data to modify
0096  */
0097 
0098 /**
0099  * \var AbstractColumnSetMaskedCmd::m_interval
0100  * \brief The interval
0101  */
0102 
0103 /**
0104  * \var AbstractColumnSetMaskedCmd::m_masked
0105  * \brief Mask/unmask flag
0106  */
0107 
0108 /**
0109  * \var AbstractColumnSetMaskedCmd::m_masking
0110  * \brief Interval attribute backup
0111  */
0112 
0113 /**
0114  * \var AbstractColumnSetMaskedCmd::m_copied
0115  * \brief A status flag
0116  */
0117 
0118 /**
0119  * \brief Ctor
0120  */
0121 AbstractColumnSetMaskedCmd::AbstractColumnSetMaskedCmd(AbstractColumnPrivate * col, const Interval<int>& interval, bool masked, QUndoCommand * parent )
0122 : QUndoCommand(parent), m_col(col), m_interval(interval), m_masked(masked) {
0123     if (masked)
0124         setText(i18n("%1: mask cells", col->name()));
0125     else
0126         setText(i18n("%1: unmask cells", col->name()));
0127     m_copied = false;
0128 }
0129 
0130 /**
0131  * \brief Dtor
0132  */
0133 AbstractColumnSetMaskedCmd::~AbstractColumnSetMaskedCmd()
0134 = default;
0135 
0136 /**
0137  * \brief Execute the command
0138  */
0139 void AbstractColumnSetMaskedCmd::redo() {
0140     if (!m_copied) {
0141         m_masking = m_col->m_masking;
0142         m_copied = true;
0143     }
0144     m_col->m_masking.setValue(m_interval, m_masked);
0145     emit m_col->owner()->dataChanged(m_col->owner());
0146 }
0147 
0148 /**
0149  * \brief Undo the command
0150  */
0151 void AbstractColumnSetMaskedCmd::undo() {
0152     m_col->m_masking = m_masking;
0153     emit m_col->owner()->dataChanged(m_col->owner());
0154 }
0155 
0156 /** ***************************************************************************
0157  * \class AbstractColumnInsertRowsCmd
0158  * \brief Insert empty rows into a column
0159  ** ***************************************************************************/
0160 
0161 /**
0162  * \var AbstractColumnInsertRowsCmd::m_col
0163  * \brief Private object of AbstractColumn to be modified.
0164  */
0165 
0166 /**
0167  * \var AbstractColumnInsertRowsCmd::m_before
0168  * \brief Row number before which to insert the new rows.
0169  */
0170 
0171 /**
0172  * \var AbstractColumnInsertRowsCmd::m_count
0173  * \brief Number of rows to be inserted.
0174  */
0175 
0176 /**
0177  * \brief Ctor
0178  */
0179 AbstractColumnInsertRowsCmd::AbstractColumnInsertRowsCmd(AbstractColumn *col, int before,
0180         int count, QUndoCommand *parent) :
0181     QUndoCommand(parent),
0182     m_col(col->d),
0183     m_before(before),
0184     m_count(count) {
0185 }
0186 
0187 /**
0188  * \brief Dtor
0189  */
0190 AbstractColumnInsertRowsCmd::~AbstractColumnInsertRowsCmd() = default;
0191 
0192 void AbstractColumnInsertRowsCmd::redo() {
0193     m_col->m_masking.insertRows(m_before, m_count);
0194 }
0195 
0196 void AbstractColumnInsertRowsCmd::undo() {
0197     m_col->m_masking.removeRows(m_before, m_count);
0198 }
0199 
0200 /** ***************************************************************************
0201  * \class AbstractColumnRemoveRowsCmd
0202  * \brief Remove rows from a column
0203  *
0204  * See AbstractColumnInsertRowsCmd for a discussion of the design.
0205  ** ***************************************************************************/
0206 
0207 /**
0208  * \var AbstractColumnRemoveRowsCmd::m_col
0209  * \brief Private object of AbstractColumn to be modified.
0210  */
0211 
0212 /**
0213  * \var AbstractColumnRemoveRowsCmd::m_first
0214  * \brief First row number to be removed.
0215  */
0216 
0217 /**
0218  * \var AbstractColumnRemoveRowsCmd::m_count
0219  * \brief Number of rows to be removed.
0220  */
0221 
0222 /**
0223  * \brief Ctor
0224  */
0225 AbstractColumnRemoveRowsCmd::AbstractColumnRemoveRowsCmd(AbstractColumn *col, int first,
0226         int count, QUndoCommand *parent) :
0227     QUndoCommand(parent),
0228     m_col(col->d),
0229     m_first(first),
0230     m_count(count) {
0231 }
0232 
0233 /**
0234  * \brief Dtor
0235  */
0236 AbstractColumnRemoveRowsCmd::~AbstractColumnRemoveRowsCmd() = default;
0237 
0238 void AbstractColumnRemoveRowsCmd::redo() {
0239     m_masking = m_col->m_masking;
0240     m_col->m_masking.removeRows(m_first, m_count);
0241 }
0242 
0243 void AbstractColumnRemoveRowsCmd::undo() {
0244     m_col->m_masking = m_masking;
0245 }
0246