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

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 "ValidityCommand.h"
0022 
0023 
0024 #include <KLocalizedString>
0025 
0026 #include "CellStorage.h"
0027 #include "Sheet.h"
0028 #include "ValidityStorage.h"
0029 
0030 using namespace Calligra::Sheets;
0031 
0032 ValidityCommand::ValidityCommand()
0033         : AbstractRegionCommand()
0034 {
0035 }
0036 
0037 bool ValidityCommand::process(Element* element)
0038 {
0039     if (!m_reverse) {
0040         // create undo
0041         if (m_firstrun)
0042             m_undoData += m_sheet->validityStorage()->undoData(Region(element->rect()));
0043         m_sheet->cellStorage()->setValidity(Region(element->rect()), m_validity);
0044     }
0045     return true;
0046 }
0047 
0048 bool ValidityCommand::mainProcessing()
0049 {
0050     if (m_reverse) {
0051         m_sheet->cellStorage()->setValidity(*this, Validity());
0052         for (int i = 0; i < m_undoData.count(); ++i)
0053             m_sheet->cellStorage()->setValidity(Region(m_undoData[i].first.toRect()), m_undoData[i].second);
0054     }
0055     return AbstractRegionCommand::mainProcessing();
0056 }
0057 
0058 void ValidityCommand::setValidity(Validity validity)
0059 {
0060     m_validity = validity;
0061     if (m_validity.isEmpty())
0062         setText(kundo2_i18n("Remove Validity Check"));
0063     else
0064         setText(kundo2_i18n("Add Validity Check"));
0065 }