Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKActionCollectionPrivate Class Reference

Public Member Functions

void _k_actionDestroyed (QObject *obj)
 
void _k_associatedWidgetDestroyed (QObject *obj)
 
 KisKActionCollectionPrivate ()
 
void setComponentForAction (QAction *action)
 
QAction * unlistAction (QObject *)
 
bool writeKisKXMLGUIConfigFile ()
 

Public Attributes

QMap< QString, QAction * > actionByName
 
QList< QAction * > actions
 
QList< QWidget * > associatedWidgets
 
QString configGroup
 
bool connectHovered {false}
 
bool connectTriggered {false}
 
QString m_componentDisplayName
 
QString m_componentName
 
const KisKXMLGUIClientm_parentGUIClient {nullptr}
 
KisKActionCollectionq {nullptr}
 

Static Public Attributes

static QList< KisKActionCollection * > s_allCollections
 

Detailed Description

Definition at line 42 of file kactioncollection.cpp.

Constructor & Destructor Documentation

◆ KisKActionCollectionPrivate()

KisKActionCollectionPrivate::KisKActionCollectionPrivate ( )
inline

Definition at line 45 of file kactioncollection.cpp.

47 configGroup(QStringLiteral("Shortcuts")),
48 q(0)
49
50 {
51 }
const KisKXMLGUIClient * m_parentGUIClient

Member Function Documentation

◆ _k_actionDestroyed()

void KisKActionCollectionPrivate::_k_actionDestroyed ( QObject * obj)

Definition at line 608 of file kactioncollection.cpp.

609{
610 unlistAction(obj);
611}
QAction * unlistAction(QObject *)

References unlistAction().

◆ _k_associatedWidgetDestroyed()

void KisKActionCollectionPrivate::_k_associatedWidgetDestroyed ( QObject * obj)

Definition at line 735 of file kactioncollection.cpp.

736{
737 associatedWidgets.removeAll(static_cast<QWidget *>(obj));
738}
QList< QWidget * > associatedWidgets

References associatedWidgets.

◆ setComponentForAction()

void KisKActionCollectionPrivate::setComponentForAction ( QAction * action)
inline

Definition at line 53 of file kactioncollection.cpp.

54 {
55 Q_UNUSED(action);
56 }

◆ unlistAction()

QAction * KisKActionCollectionPrivate::unlistAction ( QObject * action)

Remove a action from our internal bookkeeping. Returns 0 if the action doesn't belong to us.

Definition at line 674 of file kactioncollection.cpp.

675{
676 // ATTENTION:
677 // This method is called with an QObject formerly known as a QAction
678 // during _k_actionDestroyed(). So don't do fancy stuff here that needs a
679 // real QAction!
680
681 // Get the index for the action
682 const auto indexOf = [&](const QObject *action, int from = 0) -> int {
683 for (int i = from; i < actions.size(); i++) {
684 if (actions[i] == action) {
685 return i;
686 }
687 }
688 return -1;
689 };
690
691 int index = indexOf(action);
692
693 // Action not found.
694 if (index == -1) {
695 return 0;
696 }
697
698 // An action collection can't have the same action twice.
699 Q_ASSERT(indexOf(action, index + 1) == -1);
700
701 // Get the actions name
702 const QString name = action->objectName();
703
704 // Remove the action
705 actionByName.remove(name);
706 // Retrieve the typed QObject* pointer
707 // ATTENTION: THIS ACTION IS PARTIALLY DESTROYED!
708 QAction *tmp = actions.at(index);
709 actions.removeAt(index);
710
711 // Remove the action from the categories. Should be only one
712 QList<KisKActionCategory *> categories = q->findChildren<KisKActionCategory *>();
713 Q_FOREACH (KisKActionCategory *category, categories) {
714 category->unlistAction(tmp);
715 }
716
717 return tmp;
718}
void unlistAction(QAction *action)
QMap< QString, QAction * > actionByName
const char * name(StandardAction id)

References actionByName, actions, q, and KisKActionCategory::unlistAction().

◆ writeKisKXMLGUIConfigFile()

bool KisKActionCollectionPrivate::writeKisKXMLGUIConfigFile ( )

Definition at line 455 of file kactioncollection.cpp.

456{
457 const KisKXMLGUIClient *kxmlguiClient = q->parentGUIClient();
458 // return false if there is no KisKXMLGUIClient
459 if (!kxmlguiClient || kxmlguiClient->xmlFile().isEmpty()) {
460 return false;
461 }
462
463
464 QString attrShortcut = QStringLiteral("shortcut");
465
466 // Read XML file
467 QString sXml(KisKXMLGUIFactory::readConfigFile(kxmlguiClient->xmlFile(), q->componentName()));
468 QDomDocument doc;
469 doc.setContent(sXml);
470
471 // Process XML data
472
473 // Get hold of ActionProperties tag
474 QDomElement elem = KisKXMLGUIFactory::actionPropertiesElement(doc);
475
476 // now, iterate through our actions
477 for (QMap<QString, QAction *>::ConstIterator it = actionByName.constBegin();
478 it != actionByName.constEnd(); ++it) {
479 QAction *action = it.value();
480 if (!action) {
481 continue;
482 }
483
484 QString actionName = it.key();
485
486 // If the action name starts with unnamed- spit out a warning and ignore
487 // it. That name will change at will and will break loading writing
488 if (actionName.startsWith(QLatin1String("unnamed-"))) {
489 qCritical() << "Skipped writing shortcut for action " << actionName << "(" << action->text() << ")!";
490 continue;
491 }
492
493 bool bSameAsDefault = (action->shortcuts() == q->defaultShortcuts(action));
494
495 // now see if this element already exists
496 // and create it if necessary (unless bSameAsDefault)
497 QDomElement act_elem = KisKXMLGUIFactory::findActionByName(elem, actionName, !bSameAsDefault);
498 if (act_elem.isNull()) {
499 continue;
500 }
501
502 if (bSameAsDefault) {
503 act_elem.removeAttribute(attrShortcut);
504 if (act_elem.attributes().count() == 1) {
505 elem.removeChild(act_elem);
506 }
507 } else {
508 act_elem.setAttribute(attrShortcut, QKeySequence::listToString(action->shortcuts()));
509 }
510 }
511
512 // Write back to XML file
514 return true;
515}
QList< QKeySequence > defaultShortcuts(QAction *action) const
QString componentName() const
const KisKXMLGUIClient * parentGUIClient() const
virtual QString xmlFile() const
virtual QString localXMLFile() const
static QDomElement actionPropertiesElement(QDomDocument &doc)
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const QString &componentName=QString())
static QString readConfigFile(const QString &filename, const QString &componentName=QString())
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)

References actionByName, KisKXMLGUIFactory::actionPropertiesElement(), KisKActionCollection::componentName(), KisKActionCollection::defaultShortcuts(), KisKXMLGUIFactory::findActionByName(), KisKXMLGUIClient::localXMLFile(), KisKActionCollection::parentGUIClient(), q, KisKXMLGUIFactory::readConfigFile(), KisKXMLGUIFactory::saveConfigFile(), and KisKXMLGUIClient::xmlFile().

Member Data Documentation

◆ actionByName

QMap<QString, QAction *> KisKActionCollectionPrivate::actionByName

Definition at line 72 of file kactioncollection.cpp.

◆ actions

QList<QAction *> KisKActionCollectionPrivate::actions

Definition at line 73 of file kactioncollection.cpp.

◆ associatedWidgets

QList<QWidget *> KisKActionCollectionPrivate::associatedWidgets

Definition at line 84 of file kactioncollection.cpp.

◆ configGroup

QString KisKActionCollectionPrivate::configGroup

Definition at line 77 of file kactioncollection.cpp.

◆ connectHovered

bool KisKActionCollectionPrivate::connectHovered {false}

Definition at line 80 of file kactioncollection.cpp.

80{false};

◆ connectTriggered

bool KisKActionCollectionPrivate::connectTriggered {false}

Definition at line 79 of file kactioncollection.cpp.

79{false};

◆ m_componentDisplayName

QString KisKActionCollectionPrivate::m_componentDisplayName

Definition at line 66 of file kactioncollection.cpp.

◆ m_componentName

QString KisKActionCollectionPrivate::m_componentName

Definition at line 65 of file kactioncollection.cpp.

◆ m_parentGUIClient

const KisKXMLGUIClient* KisKActionCollectionPrivate::m_parentGUIClient {nullptr}

Definition at line 75 of file kactioncollection.cpp.

75{nullptr};

◆ q

KisKActionCollection* KisKActionCollectionPrivate::q {nullptr}

Definition at line 82 of file kactioncollection.cpp.

82{nullptr};

◆ s_allCollections

QList< KisKActionCollection * > KisKActionCollectionPrivate::s_allCollections
static

Definition at line 58 of file kactioncollection.cpp.


The documentation for this class was generated from the following file: