diff --git a/src/PlanMacros.h b/src/PlanMacros.h index 1c868a62..a63e81f2 100644 --- a/src/PlanMacros.h +++ b/src/PlanMacros.h @@ -1,26 +1,34 @@ /* This file is part of the KDE project Copyright (C) 2004, 2007 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef PLANMACROS_H #define PLANMACROS_H #define CONTAINS(list, value) std::find(list.cbegin(), list.cend(), value) != list.cend() +#define OBJECTCONNECTIONS QList ObjectConnections; + +#define CONNECT_TYPE(sender, signal, context, functor, type) ObjectConnections << connect(sender, signal, context, functor, type) + +#define CONNECT(sender, signal, context, functor) ObjectConnections << connect(sender, signal, context, functor, Qt::AutoConnection) + +#define DISCONNECT for (const QMetaObject::Connection &c : qAsConst(ObjectConnections)) { disconnect(c); } + #endif diff --git a/src/libs/ui/kpttaskdescriptiondialog.cpp b/src/libs/ui/kpttaskdescriptiondialog.cpp index 6fe9f376..2745afd3 100644 --- a/src/libs/ui/kpttaskdescriptiondialog.cpp +++ b/src/libs/ui/kpttaskdescriptiondialog.cpp @@ -1,172 +1,177 @@ /* This file is part of the KDE project Copyright (C) 2009 Dag Andersen #include #include namespace KPlato { TaskDescriptionPanel::TaskDescriptionPanel(Node &node, QWidget *p, bool readOnly ) : TaskDescriptionPanelImpl( node, p ) { initDescription( readOnly ); setStartValues( node ); descriptionfield->setFocus(); } void TaskDescriptionPanel::setStartValues( Node &node ) { namefield->setText(node.name()); descriptionfield->setTextOrHtml( node.description() ); } MacroCommand *TaskDescriptionPanel::buildCommand() { KUndo2MagicString s = kundo2_i18n("Modify task description"); if ( m_node.type() == Node::Type_Milestone ) { s = kundo2_i18n("Modify milestone description"); } else if ( m_node.type() == Node::Type_Summarytask ) { s = kundo2_i18n("Modify summary task description"); } else if ( m_node.type() == Node::Type_Project ) { s = kundo2_i18n("Modify project description"); } MacroCommand *cmd = new MacroCommand(s); bool modified = false; if ( m_node.description() != descriptionfield->textOrHtml() ) { cmd->addCommand(new NodeModifyDescriptionCmd(m_node, descriptionfield->textOrHtml())); modified = true; } if (!modified) { delete cmd; return 0; } return cmd; } bool TaskDescriptionPanel::ok() { return true; } void TaskDescriptionPanel::initDescription( bool readOnly ) { toolbar->setVisible( ! readOnly ); toolbar->setToolButtonStyle( Qt::ToolButtonIconOnly ); KActionCollection *collection = new KActionCollection( this ); //krazy:exclude=tipsandthis descriptionfield->setRichTextSupport( KRichTextWidget::SupportBold | KRichTextWidget::SupportItalic | KRichTextWidget::SupportUnderline | KRichTextWidget::SupportStrikeOut | KRichTextWidget::SupportChangeListStyle | KRichTextWidget::SupportAlignment | KRichTextWidget::SupportFormatPainting ); collection->addActions(descriptionfield->createActions()); toolbar->addAction( collection->action( "format_text_bold" ) ); toolbar->addAction( collection->action( "format_text_italic" ) ); toolbar->addAction( collection->action( "format_text_underline" ) ); toolbar->addAction( collection->action( "format_text_strikeout" ) ); toolbar->addSeparator(); toolbar->addAction( collection->action( "format_list_style" ) ); toolbar->addSeparator(); toolbar->addAction( collection->action( "format_align_left" ) ); toolbar->addAction( collection->action( "format_align_center" ) ); toolbar->addAction( collection->action( "format_align_right" ) ); toolbar->addAction( collection->action( "format_align_justify" ) ); toolbar->addSeparator(); // toolbar->addAction( collection->action( "format_painter" ) ); descriptionfield->append( "" ); descriptionfield->setReadOnly( readOnly ); descriptionfield->setOverwriteMode( false ); descriptionfield->setLineWrapMode( KTextEdit::WidgetWidth ); descriptionfield->setTabChangesFocus( true ); } //----------------------------- TaskDescriptionPanelImpl::TaskDescriptionPanelImpl( Node &node, QWidget *p ) : QWidget(p), m_node(node) { setupUi(this); - connect( descriptionfield, &QTextEdit::textChanged, this, &TaskDescriptionPanelImpl::slotChanged ); + CONNECT(descriptionfield, &QTextEdit::textChanged, this, &TaskDescriptionPanelImpl::slotChanged); +} + +TaskDescriptionPanelImpl::~TaskDescriptionPanelImpl() +{ + DISCONNECT; } void TaskDescriptionPanelImpl::slotChanged() { emit textChanged( descriptionfield->textOrHtml() != m_node.description() ); } //----------------------------- TaskDescriptionDialog::TaskDescriptionDialog( Task &task, QWidget *p, bool readOnly ) : KoDialog(p) { setCaption( i18n( "Task Description" ) ); if ( readOnly ) { setButtons( Close ); } else { setButtons( Ok|Cancel ); setDefaultButton( Ok ); } showButtonSeparator( true ); m_descriptionTab = new TaskDescriptionPanel( task, this, readOnly ); setMainWidget(m_descriptionTab); enableButtonOk(false); connect( m_descriptionTab, &TaskDescriptionPanelImpl::textChanged, this, &KoDialog::enableButtonOk ); } MacroCommand *TaskDescriptionDialog::buildCommand() { return m_descriptionTab->buildCommand(); } void TaskDescriptionDialog::slotButtonClicked( int button ) { if (button == KoDialog::Ok) { if ( ! m_descriptionTab->ok() ) { return; } accept(); } else { KoDialog::slotButtonClicked( button ); } } } //KPlato namespace diff --git a/src/libs/ui/kpttaskdescriptiondialog.h b/src/libs/ui/kpttaskdescriptiondialog.h index d4cb37db..5300f89f 100644 --- a/src/libs/ui/kpttaskdescriptiondialog.h +++ b/src/libs/ui/kpttaskdescriptiondialog.h @@ -1,92 +1,97 @@ /* This file is part of the KDE project Copyright (C) 2009 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KPTTASKDESCRIPTIONDIALOG_H #define KPTTASKDESCRIPTIONDIALOG_H #include "planui_export.h" +#include "PlanMacros.h" #include "ui_kpttaskdescriptionpanelbase.h" #include namespace KPlato { class TaskDescriptionPanel; class Task; class Node; class MacroCommand; class TaskDescriptionPanelImpl : public QWidget, public Ui_TaskDescriptionPanelBase { Q_OBJECT public: TaskDescriptionPanelImpl( Node &node, QWidget *parent ); + ~TaskDescriptionPanelImpl(); public Q_SLOTS: virtual void slotChanged(); Q_SIGNALS: void textChanged( bool ); protected: Node &m_node; + +private: + OBJECTCONNECTIONS; }; class TaskDescriptionPanel : public TaskDescriptionPanelImpl { Q_OBJECT public: explicit TaskDescriptionPanel( Node &node, QWidget *parent = 0, bool readOnly = false ); MacroCommand *buildCommand(); bool ok(); void setStartValues( Node &node ); protected: void initDescription( bool readOnly ); }; class PLANUI_EXPORT TaskDescriptionDialog : public KoDialog { Q_OBJECT public: /** * The constructor for the task description dialog. * @param task the node to show * @param parent parent widget * @param readOnly determines whether the data are read-only */ explicit TaskDescriptionDialog( Task &task, QWidget *parent = 0, bool readOnly = false ); MacroCommand *buildCommand(); protected Q_SLOTS: void slotButtonClicked( int button ); protected: TaskDescriptionPanel *m_descriptionTab; }; } //KPlato namespace #endif // KPTTASKDESCRIPTIONDIALOG_H