File indexing completed on 2024-05-12 15:27:02
0001 /*************************************************************************** 0002 File : matrixcommands.cpp 0003 Project : LabPlot 0004 Description : Commands used in Matrix (part of the undo/redo framework) 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2008 Tilman Benkert (thzs@gmx.net) 0007 Copyright : (C) 2015 Alexander Semke (alexander.semke@web.de) 0008 Copyright : (C) 2017 Stefan Gerlach (stefan.gerlach@uni.kn) 0009 0010 ***************************************************************************/ 0011 0012 /*************************************************************************** 0013 * * 0014 * This program is free software; you can redistribute it and/or modify * 0015 * it under the terms of the GNU General Public License as published by * 0016 * the Free Software Foundation; either version 2 of the License, or * 0017 * (at your option) any later version. * 0018 * * 0019 * This program is distributed in the hope that it will be useful, * 0020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0022 * GNU General Public License for more details. * 0023 * * 0024 * You should have received a copy of the GNU General Public License * 0025 * along with this program; if not, write to the Free Software * 0026 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0027 * Boston, MA 02110-1301 USA * 0028 * * 0029 ***************************************************************************/ 0030 0031 #include "matrixcommands.h" 0032 #include "MatrixPrivate.h" 0033 0034 //Insert columns 0035 MatrixInsertColumnsCmd::MatrixInsertColumnsCmd(MatrixPrivate* private_obj, int before, int count, QUndoCommand* parent) 0036 : QUndoCommand(parent), m_private_obj(private_obj), m_before(before), m_count(count) { 0037 setText(i18np("%1: insert %2 column", "%1: insert %2 columns", m_private_obj->name(), m_count)); 0038 } 0039 0040 void MatrixInsertColumnsCmd::redo() { 0041 m_private_obj->insertColumns(m_before, m_count); 0042 emit m_private_obj->q->columnCountChanged(m_private_obj->columnCount); 0043 } 0044 0045 void MatrixInsertColumnsCmd::undo() { 0046 m_private_obj->removeColumns(m_before, m_count); 0047 emit m_private_obj->q->columnCountChanged(m_private_obj->columnCount); 0048 } 0049 0050 //Insert rows 0051 MatrixInsertRowsCmd::MatrixInsertRowsCmd(MatrixPrivate* private_obj, int before, int count, QUndoCommand* parent) 0052 : QUndoCommand(parent), m_private_obj(private_obj), m_before(before), m_count(count) { 0053 setText(i18np("%1: insert %2 row", "%1: insert %2 rows", m_private_obj->name(), m_count)); 0054 } 0055 0056 void MatrixInsertRowsCmd::redo() { 0057 m_private_obj->insertRows(m_before, m_count); 0058 emit m_private_obj->q->rowCountChanged(m_private_obj->rowCount); 0059 } 0060 0061 void MatrixInsertRowsCmd::undo() { 0062 m_private_obj->removeRows(m_before, m_count); 0063 emit m_private_obj->q->rowCountChanged(m_private_obj->rowCount); 0064 } 0065 0066 //set coordinates 0067 MatrixSetCoordinatesCmd::MatrixSetCoordinatesCmd(MatrixPrivate* private_obj, double x1, double x2, double y1, double y2, QUndoCommand* parent) 0068 : QUndoCommand( parent ), m_private_obj(private_obj), m_new_x1(x1), m_new_x2(x2), m_new_y1(y1), m_new_y2(y2) { 0069 setText(i18n("%1: set matrix coordinates", m_private_obj->name())); 0070 } 0071 0072 void MatrixSetCoordinatesCmd::redo() { 0073 m_old_x1 = m_private_obj->xStart; 0074 m_old_x2 = m_private_obj->xEnd; 0075 m_old_y1 = m_private_obj->yStart; 0076 m_old_y2 = m_private_obj->yEnd; 0077 m_private_obj->xStart = m_new_x1; 0078 m_private_obj->xEnd = m_new_x2; 0079 m_private_obj->yStart = m_new_y1; 0080 m_private_obj->yEnd = m_new_y2; 0081 } 0082 0083 void MatrixSetCoordinatesCmd::undo() { 0084 m_private_obj->xStart = m_old_x1; 0085 m_private_obj->xEnd = m_old_x2; 0086 m_private_obj->yStart = m_old_y1; 0087 m_private_obj->yEnd = m_old_y2; 0088 } 0089 0090 //set formula 0091 MatrixSetFormulaCmd::MatrixSetFormulaCmd(MatrixPrivate* private_obj, QString formula) 0092 : m_private_obj(private_obj), m_other_formula(std::move(formula)) { 0093 setText(i18n("%1: set formula", m_private_obj->name())); 0094 } 0095 0096 void MatrixSetFormulaCmd::redo() { 0097 QString tmp = m_private_obj->formula; 0098 m_private_obj->formula = m_other_formula; 0099 m_other_formula = tmp; 0100 } 0101 0102 void MatrixSetFormulaCmd::undo() { 0103 redo(); 0104 } 0105 0106 //replace values 0107 MatrixReplaceValuesCmd::MatrixReplaceValuesCmd(MatrixPrivate* private_obj, void* new_values, QUndoCommand* parent) 0108 : QUndoCommand(parent), m_private_obj(private_obj), m_new_values(new_values) { 0109 setText(i18n("%1: replace values", m_private_obj->name())); 0110 } 0111 0112 void MatrixReplaceValuesCmd::redo() { 0113 m_old_values = m_private_obj->data; 0114 m_private_obj->data = m_new_values; 0115 m_private_obj->emitDataChanged(0, 0, m_private_obj->rowCount -1, m_private_obj->columnCount-1); 0116 } 0117 0118 void MatrixReplaceValuesCmd::undo() { 0119 m_new_values = m_private_obj->data; 0120 m_private_obj->data = m_old_values; 0121 m_private_obj->emitDataChanged(0, 0, m_private_obj->rowCount -1, m_private_obj->columnCount-1); 0122 }