File indexing completed on 2024-05-12 16:35:09
0001 /* This file is part of the KDE project 0002 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 2006 Thomas Zander <zander@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "ChartDatabaseSelector.h" 0022 0023 #include "ui_ChartDatabaseSelector.h" 0024 0025 #include "KoCanvasResourceIdentities.h" 0026 #include "KoCanvasResourceManager.h" 0027 #include "KoShape.h" 0028 0029 #include "KoChartInterface.h" 0030 0031 #include "Binding.h" 0032 #include "CellStorage.h" 0033 #include "Region.h" 0034 #include "ui/Selection.h" 0035 #include "Sheet.h" 0036 #include "DocBase.h" 0037 #include "SheetAccessModel.h" 0038 #include "odf/SheetsOdf.h" 0039 0040 using namespace Calligra::Sheets; 0041 0042 class ChartDatabaseSelector::Private 0043 { 0044 public: 0045 Map* map; 0046 Selection* selection; 0047 KoChart::ChartInterface* shape; 0048 Ui::ChartDatabaseSelector widget; 0049 }; 0050 0051 ChartDatabaseSelector::ChartDatabaseSelector(Map *map) 0052 : KoShapeConfigWidgetBase() 0053 , d(new Private) 0054 { 0055 d->map = map; 0056 d->selection = 0; 0057 d->shape = 0; 0058 d->widget.setupUi(this); 0059 } 0060 0061 ChartDatabaseSelector::~ChartDatabaseSelector() 0062 { 0063 delete d; 0064 } 0065 0066 void ChartDatabaseSelector::open(KoShape* shape) 0067 { 0068 QObject* const object = dynamic_cast<QObject*>(shape); 0069 Q_ASSERT(object); 0070 if (!object) { 0071 return; 0072 } 0073 d->shape = qobject_cast<KoChart::ChartInterface*>(object); 0074 Q_ASSERT(d->shape); 0075 } 0076 0077 void ChartDatabaseSelector::save() 0078 { 0079 Sheet *sheet = d->selection->activeSheet(); 0080 const Region selectedRegion(d->widget.m_cellRegion->text(), d->map, sheet); 0081 if(!selectedRegion.isValid()) 0082 return; 0083 0084 d->shape->setSheetAccessModel(sheet->doc()->sheetAccessModel()); 0085 d->shape->reset(Odf::saveRegion(selectedRegion.name()), 0086 d->widget.m_firstRowAsLabel->isChecked(), 0087 d->widget.m_firstColumnAsLabel->isChecked(), 0088 d->widget.m_dataInRows->isChecked() ? Qt::Horizontal : Qt::Vertical); 0089 } 0090 0091 void ChartDatabaseSelector::showEvent(QShowEvent* event) 0092 { 0093 Q_UNUSED(event); 0094 Q_ASSERT(m_resourceManager); 0095 d->selection = static_cast<Selection*>(m_resourceManager->resource(::Sheets::CanvasResource::Selection).value<void*>()); 0096 d->widget.m_cellRegion->setText(d->selection->Region::name()); 0097 }