File indexing completed on 2024-04-28 04:36:29
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "iassistant.h" 0008 #include "icore.h" 0009 0010 #include <QAction> 0011 #include <QThread> 0012 0013 using namespace KDevelop; 0014 0015 Q_DECLARE_METATYPE(QExplicitlySharedDataPointer<IAssistantAction>) 0016 0017 //BEGIN IAssistant 0018 0019 void IAssistant::createActions() 0020 { 0021 } 0022 0023 QAction* IAssistantAction::toQAction(QObject* parent) const 0024 { 0025 Q_ASSERT(QThread::currentThread() == ICore::self()->thread() && "Actions must be created in the application main thread" 0026 "(implement createActions() to create your actions)"); 0027 0028 auto* ret = new QAction(icon(), description(), parent); 0029 ret->setToolTip(toolTip()); 0030 0031 //Add the data as a QExplicitlySharedDataPointer to the action, so this assistant stays alive at least as long as the QAction 0032 ret->setData(QVariant::fromValue(QExplicitlySharedDataPointer<IAssistantAction>(const_cast<IAssistantAction*>(this)))); 0033 0034 connect(ret, &QAction::triggered, this, &IAssistantAction::execute); 0035 return ret; 0036 } 0037 0038 IAssistant::~IAssistant() 0039 { 0040 } 0041 0042 IAssistantAction::IAssistantAction() 0043 : QObject() 0044 , KSharedObject(*(QObject*)this) 0045 { 0046 } 0047 0048 IAssistantAction::~IAssistantAction() 0049 { 0050 } 0051 0052 QIcon IAssistantAction::icon() const 0053 { 0054 return QIcon(); 0055 } 0056 0057 QString IAssistantAction::toolTip() const 0058 { 0059 return QString(); 0060 } 0061 0062 //END IAssistantAction 0063 0064 //BEGIN AssistantLabelAction 0065 0066 AssistantLabelAction::AssistantLabelAction(const QString& description) 0067 : m_description(description) 0068 { 0069 0070 } 0071 0072 QString AssistantLabelAction::description() const 0073 { 0074 return m_description; 0075 } 0076 0077 void AssistantLabelAction::execute() 0078 { 0079 // do nothing 0080 } 0081 0082 QAction* AssistantLabelAction::toQAction(QObject* parent) const 0083 { 0084 Q_UNUSED(parent); 0085 return nullptr; 0086 } 0087 0088 //END AssistantLabelAction 0089 0090 //BEGIN: IAssistant 0091 0092 IAssistant::IAssistant() 0093 : KSharedObject(*(QObject*)this) 0094 { 0095 } 0096 0097 QIcon IAssistant::icon() const 0098 { 0099 return QIcon(); 0100 } 0101 0102 QString IAssistant::title() const 0103 { 0104 return QString(); 0105 } 0106 0107 void IAssistant::doHide() 0108 { 0109 emit hide(); 0110 } 0111 0112 QList< IAssistantAction::Ptr > IAssistant::actions() const 0113 { 0114 if ( m_actions.isEmpty() ) { 0115 const_cast<IAssistant*>(this)->createActions(); 0116 } 0117 return m_actions; 0118 } 0119 0120 void IAssistant::addAction(const IAssistantAction::Ptr& action) 0121 { 0122 m_actions << action; 0123 } 0124 0125 void IAssistant::clearActions() 0126 { 0127 m_actions.clear(); 0128 } 0129 0130 //END IAssistant 0131 0132 #include "moc_iassistant.cpp"