File indexing completed on 2024-05-12 16:35:11

0001 /* This file is part of the KDE project
0002    Copyright 2005,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 // Local
0021 #include "ConditionCommand.h"
0022 
0023 #include <KLocalizedString>
0024 
0025 #include "CellStorage.h"
0026 #include "ConditionsStorage.h"
0027 #include "Sheet.h"
0028 
0029 using namespace Calligra::Sheets;
0030 
0031 ConditionCommand::ConditionCommand()
0032         : AbstractRegionCommand()
0033 {
0034 }
0035 
0036 bool ConditionCommand::process(Element* element)
0037 {
0038     if (!m_reverse) {
0039         // create undo
0040         if (m_firstrun)
0041             m_undoData += m_sheet->conditionsStorage()->undoData(Region(element->rect()));
0042         m_sheet->cellStorage()->setConditions(Region(element->rect()), m_conditions);
0043     }
0044     return true;
0045 }
0046 
0047 bool ConditionCommand::mainProcessing()
0048 {
0049     if (m_reverse) {
0050         m_sheet->cellStorage()->setConditions(*this, Conditions());
0051         for (int i = 0; i < m_undoData.count(); ++i)
0052             m_sheet->cellStorage()->setConditions(Region(m_undoData[i].first.toRect()), m_undoData[i].second);
0053     }
0054     return AbstractRegionCommand::mainProcessing();
0055 }
0056 
0057 void ConditionCommand::setConditionList(const QLinkedList<Conditional>& list)
0058 {
0059     m_conditions.setConditionList(list);
0060     if (m_conditions.isEmpty())
0061         setText(kundo2_i18n("Remove Conditional Formatting"));
0062     else
0063         setText(kundo2_i18n("Add Conditional Formatting"));
0064 }