File indexing completed on 2024-05-12 15:28:01

0001 /***************************************************************************
0002     File                 : ProjectDock.cpp
0003     Project              : LabPlot
0004     Description          : widget for project properties
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2012-2013 by Stefan Gerlach (stefan.gerlach@uni-konstanz.de)
0007     Copyright            : (C) 2013-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 "ProjectDock.h"
0031 #include "backend/core/Project.h"
0032 #include "kdefrontend/TemplateHandler.h"
0033 #include <KConfigGroup>
0034 #include <KConfig>
0035 
0036 /*!
0037   \class ProjectDock
0038   \brief Provides a widget for editing the properties of a project
0039 
0040   \ingroup kdefrontend
0041 */
0042 
0043 ProjectDock::ProjectDock(QWidget* parent) : BaseDock(parent) {
0044     ui.setupUi(this);
0045     m_leName = ui.leName;
0046     // leComment = ui.tbComment; // not a qlineedit
0047 
0048     // SLOTS
0049     connect(ui.leName, &QLineEdit::textChanged, this, &ProjectDock::nameChanged);
0050     connect(ui.leAuthor, &QLineEdit::textChanged, this, &ProjectDock::authorChanged);
0051     connect(ui.tbComment, &QTextBrowser::textChanged, this, &ProjectDock::commentChanged);
0052 
0053     auto* templateHandler = new TemplateHandler(this, TemplateHandler::ClassName::Worksheet);
0054     ui.verticalLayout->addWidget(templateHandler);
0055     templateHandler->show();
0056     connect(templateHandler, &TemplateHandler::loadConfigRequested, this, &ProjectDock::loadConfig);
0057     connect(templateHandler, &TemplateHandler::saveConfigRequested, this, &ProjectDock::saveConfig);
0058 
0059     this->retranslateUi();
0060 }
0061 
0062 void ProjectDock::setProject(Project* project) {
0063     m_project = project;
0064     m_aspect = project;
0065 
0066     m_initializing = true;
0067     ui.leFileName->setText(project->fileName());
0068     ui.leName->setStyleSheet("");
0069     ui.leName->setToolTip("");
0070     ui.lVersion->setText(project->version());
0071     ui.lCreated->setText(project->creationTime().toString());
0072     ui.lModified->setText(project->modificationTime().toString());
0073 
0074     //show default properties of the project
0075     KConfig config(QString(), KConfig::SimpleConfig);
0076     loadConfig(config);
0077 
0078     connect(m_project, &Project::aspectDescriptionChanged, this, &ProjectDock::projectDescriptionChanged);
0079     connect(m_project, &Project::authorChanged, this, &ProjectDock::projectAuthorChanged);
0080 
0081     m_initializing = false;
0082 }
0083 
0084 //************************************************************
0085 //****************** SLOTS ********************************
0086 //************************************************************
0087 void ProjectDock::retranslateUi() {
0088 }
0089 
0090 void ProjectDock::authorChanged() {
0091     if (m_initializing)
0092         return;
0093 
0094     m_project->setAuthor(ui.leAuthor->text());
0095 }
0096 
0097 void ProjectDock::commentChanged() {
0098     if (m_initializing)
0099         return;
0100 
0101     m_project->setComment(ui.tbComment->toPlainText());
0102 }
0103 
0104 //*************************************************************
0105 //******** SLOTs for changes triggered in Project   ***********
0106 //*************************************************************
0107 void ProjectDock::projectDescriptionChanged(const AbstractAspect* aspect) {
0108     if (m_project != aspect)
0109         return;
0110 
0111     m_initializing = true;
0112     if (aspect->name() != ui.leName->text())
0113         ui.leName->setText(aspect->name());
0114     else if (aspect->comment() != ui.tbComment->toPlainText())
0115         ui.tbComment->setText(aspect->comment());
0116 
0117     m_initializing = false;
0118 }
0119 
0120 void ProjectDock::projectAuthorChanged(const QString& author) {
0121     Lock lock(m_initializing);
0122     ui.leAuthor->setText(author);
0123 }
0124 //*************************************************************
0125 //************************* Settings **************************
0126 //*************************************************************
0127 void ProjectDock::loadConfig(KConfig& config) {
0128     KConfigGroup group = config.group( "Project" );
0129 
0130     ui.leName->setText( group.readEntry("Name", m_project->name()) );
0131     ui.leAuthor->setText( group.readEntry("Author", m_project->author()) );
0132     ui.tbComment->setText( group.readEntry("Comment", m_project->comment()) );
0133 }
0134 
0135 void ProjectDock::saveConfig(KConfig& config) {
0136     KConfigGroup group = config.group( "Project" );
0137 
0138     group.writeEntry("Name", ui.leName->text());
0139     group.writeEntry("Author", ui.leAuthor->text());
0140     group.writeEntry("Comment", ui.tbComment->toPlainText());
0141 }