File indexing completed on 2024-05-12 15:27:55

0001 /***************************************************************************
0002     File                 : BaseDock.cpp
0003     Project              : LabPlot
0004     Description          : Base Dock widget
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2019 Martin Marmsoler (martin.marmsoler@gmail.com)
0007     Copyright            : (C) 2019-2020 Alexander Semke (alexander.semke@web.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 "BaseDock.h"
0031 #include "backend/core/AbstractAspect.h"
0032 
0033 #include <KLocalizedString>
0034 #include <KConfigGroup>
0035 #include <KSharedConfig>
0036 
0037 BaseDock::BaseDock(QWidget* parent) : QWidget(parent) {
0038     const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
0039     m_units = (Units)group.readEntry("Units", static_cast<int>(Units::Metric));
0040 
0041     if (m_units == Units::Imperial)
0042         m_worksheetUnit = Worksheet::Unit::Inch;
0043 }
0044 
0045 BaseDock::~BaseDock() = default;
0046 
0047 void BaseDock::nameChanged() {
0048     if (m_initializing || !m_aspect)
0049         return;
0050 
0051     if (!m_aspect->setName(m_leName->text(), false)) {
0052         m_leName->setStyleSheet("background:red;");
0053         m_leName->setToolTip(i18n("Please choose another name, because this is already in use."));
0054         return;
0055     }
0056 
0057     m_leName->setStyleSheet("");
0058     m_leName->setToolTip("");
0059 }
0060 
0061 void BaseDock::commentChanged() {
0062     if (m_initializing || !m_aspect)
0063         return;
0064 
0065     m_aspect->setComment(m_leComment->text());
0066 }