Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKXMLGUIFactoryPrivate Class Reference
+ Inheritance diagram for KisKXMLGUIFactoryPrivate:

Public Types

enum  ShortcutOption { SetActiveShortcut = 1 , SetDefaultShortcut = 2 }
 

Public Member Functions

void applyActionProperties (const QDomElement &element, ShortcutOption shortcutOption=KisKXMLGUIFactoryPrivate::SetActiveShortcut)
 
void configureAction (QAction *action, const QDomAttr &attribute, ShortcutOption shortcutOption=KisKXMLGUIFactoryPrivate::SetActiveShortcut)
 
void configureAction (QAction *action, const QDomNamedNodeMap &attributes, ShortcutOption shortcutOption=KisKXMLGUIFactoryPrivate::SetActiveShortcut)
 
bool emptyState () const
 
QWidget * findRecursive (KisKXMLGUI::ContainerNode *node, bool tag)
 
QList< QWidget * > findRecursive (KisKXMLGUI::ContainerNode *node, const QString &tagName)
 
 KisKXMLGUIFactoryPrivate ()
 
void popState ()
 
void pushState ()
 
void refreshActionProperties (KisKXMLGUIClient *client, const QList< QAction * > &actions, const QDomDocument &doc)
 
void saveDefaultActionProperties (const QList< QAction * > &actions)
 
 ~KisKXMLGUIFactoryPrivate ()
 
- Public Member Functions inherited from KisKXMLGUI::BuildState
 BuildState ()
 
void reset ()
 

Public Attributes

QString attrName
 
QList< KisKXMLGUIClient * > m_clients
 
QString m_containerName
 
QString m_defaultMergingName
 
ContainerNodem_rootNode
 
BuildStateStack m_stateStack
 
QString tagActionList
 
- Public Attributes inherited from KisKXMLGUI::BuildState
ActionList actionList
 
QString actionListName
 
KisKXMLGUIBuilderbuilder
 
QStringList builderContainerTags
 
QStringList builderCustomTags
 
KisKXMLGUIBuilderclientBuilder
 
QStringList clientBuilderContainerTags
 
QStringList clientBuilderCustomTags
 
QString clientName
 
MergingIndexList::Iterator currentClientMergingIt
 
MergingIndexList::Iterator currentDefaultMergingIt
 
KisKXMLGUIClientguiClient
 

Detailed Description

Definition at line 43 of file kxmlguifactory.cpp.

Member Enumeration Documentation

◆ ShortcutOption

Enumerator
SetActiveShortcut 
SetDefaultShortcut 

Definition at line 46 of file kxmlguifactory.cpp.

Constructor & Destructor Documentation

◆ KisKXMLGUIFactoryPrivate()

KisKXMLGUIFactoryPrivate::KisKXMLGUIFactoryPrivate ( )
inline

Definition at line 48 of file kxmlguifactory.cpp.

49 {
50 m_rootNode = new ContainerNode(0L, QString(), QString());
51 m_defaultMergingName = QStringLiteral("<default>");
52 tagActionList = QStringLiteral("actionlist");
53 attrName = QStringLiteral("name");
54 }

References attrName, m_defaultMergingName, m_rootNode, and tagActionList.

◆ ~KisKXMLGUIFactoryPrivate()

KisKXMLGUIFactoryPrivate::~KisKXMLGUIFactoryPrivate ( )
inline

Definition at line 55 of file kxmlguifactory.cpp.

56 {
57 delete m_rootNode;
58 }

References m_rootNode.

Member Function Documentation

◆ applyActionProperties()

void KisKXMLGUIFactoryPrivate::applyActionProperties ( const QDomElement & element,
ShortcutOption shortcutOption = KisKXMLGUIFactoryPrivate::SetActiveShortcut )

Definition at line 577 of file kxmlguifactory.cpp.

579{
580 for (QDomElement e = actionPropElement.firstChildElement();
581 !e.isNull(); e = e.nextSiblingElement()) {
582 if (!equals(e.tagName(), "action")) {
583 continue;
584 }
585
586 QAction *action = guiClient->action(e);
587 if (!action) {
588 continue;
589 }
590
591 configureAction(action, e.attributes(), shortcutOption);
592 }
593}
QAction * action(const char *name) const
void configureAction(QAction *action, const QDomNamedNodeMap &attributes, ShortcutOption shortcutOption=KisKXMLGUIFactoryPrivate::SetActiveShortcut)
static bool equals(const QString &str1, const char *str2)
KisKXMLGUIClient * guiClient

References KisKXMLGUIClient::action(), configureAction(), equals(), and KisKXMLGUI::BuildState::guiClient.

◆ configureAction() [1/2]

void KisKXMLGUIFactoryPrivate::configureAction ( QAction * action,
const QDomAttr & attribute,
ShortcutOption shortcutOption = KisKXMLGUIFactoryPrivate::SetActiveShortcut )

Definition at line 608 of file kxmlguifactory.cpp.

610{
611 QString attrName = attribute.name();
612 // If the attribute is a deprecated "accel", change to "shortcut".
613 if (equals(attrName, "accel")) {
614 attrName = QStringLiteral("shortcut");
615 }
616
617 // No need to re-set name, particularly since it's "objectName" in Qt4
618 if (equals(attrName, "name")) {
619 return;
620 }
621
622 if (equals(attrName, "icon")) {
623 action->setIcon(KisIconUtils::loadIcon(attribute.value()));
624 return;
625 }
626
627 QVariant propertyValue;
628
629 QVariant::Type propertyType = action->property(attrName.toLatin1().constData()).type();
630 bool isShortcut = (propertyType == QVariant::KeySequence);
631
632 if (propertyType == QVariant::Int) {
633 propertyValue = QVariant(attribute.value().toInt());
634 } else if (propertyType == QVariant::UInt) {
635 propertyValue = QVariant(attribute.value().toUInt());
636 } else if (isShortcut) {
637 // Setting the shortcut by property also sets the default shortcut
638 // (which is incorrect), so we have to do it directly
639 action->setShortcuts(QKeySequence::listFromString(attribute.value()));
641 action->setProperty("defaultShortcuts",
642 QVariant::fromValue(QKeySequence::listFromString(attribute.value())));
643 }
644 } else {
645 propertyValue = QVariant(attribute.value());
646 }
647 if (!isShortcut && !action->setProperty(attrName.toLatin1().constData(), propertyValue)) {
648 qWarning() << "Error: Unknown action property " << attrName << " will be ignored!";
649 }
650}
QIcon loadIcon(const QString &name)

References attrName, equals(), KisIconUtils::loadIcon(), and SetDefaultShortcut.

◆ configureAction() [2/2]

void KisKXMLGUIFactoryPrivate::configureAction ( QAction * action,
const QDomNamedNodeMap & attributes,
ShortcutOption shortcutOption = KisKXMLGUIFactoryPrivate::SetActiveShortcut )

Definition at line 595 of file kxmlguifactory.cpp.

597{
598 for (int i = 0; i < attributes.length(); i++) {
599 QDomAttr attr = attributes.item(i).toAttr();
600 if (attr.isNull()) {
601 continue;
602 }
603
604 configureAction(action, attr, shortcutOption);
605 }
606}

References configureAction().

◆ emptyState()

bool KisKXMLGUIFactoryPrivate::emptyState ( ) const
inline

Definition at line 70 of file kxmlguifactory.cpp.

71 {
72 return m_stateStack.isEmpty();
73 }

References m_stateStack.

◆ findRecursive() [1/2]

QWidget * KisKXMLGUIFactoryPrivate::findRecursive ( KisKXMLGUI::ContainerNode * node,
bool tag )

Definition at line 501 of file kxmlguifactory.cpp.

502{
503 if (((!tag && node->name == m_containerName) ||
504 (tag && node->tagName == m_containerName)) &&
505 (!guiClient || node->client == guiClient)) {
506 return node->container;
507 }
508
509 Q_FOREACH (ContainerNode *child, node->children) {
510 QWidget *cont = findRecursive(child, tag);
511 if (cont) {
512 return cont;
513 }
514 }
515
516 return 0L;
517}
QWidget * findRecursive(KisKXMLGUI::ContainerNode *node, bool tag)
QList< ContainerNode * > children

References KisKXMLGUI::ContainerNode::children, KisKXMLGUI::ContainerNode::client, KisKXMLGUI::ContainerNode::container, findRecursive(), KisKXMLGUI::BuildState::guiClient, m_containerName, KisKXMLGUI::ContainerNode::name, and KisKXMLGUI::ContainerNode::tagName.

◆ findRecursive() [2/2]

QList< QWidget * > KisKXMLGUIFactoryPrivate::findRecursive ( KisKXMLGUI::ContainerNode * node,
const QString & tagName )

Definition at line 529 of file kxmlguifactory.cpp.

531{
533
534 if (equals(node->tagName, tagName)) {
535 res.append(node->container);
536 }
537
538 Q_FOREACH (KisKXMLGUI::ContainerNode *child, node->children) {
539 res << findRecursive(child, tagName);
540 }
541
542 return res;
543}

References KisKXMLGUI::ContainerNode::children, KisKXMLGUI::ContainerNode::container, equals(), findRecursive(), and KisKXMLGUI::ContainerNode::tagName.

◆ popState()

void KisKXMLGUIFactoryPrivate::popState ( )
inline

Definition at line 65 of file kxmlguifactory.cpp.

66 {
67 BuildState::operator=(m_stateStack.pop());
68 }

References m_stateStack.

◆ pushState()

void KisKXMLGUIFactoryPrivate::pushState ( )
inline

Definition at line 60 of file kxmlguifactory.cpp.

61 {
62 m_stateStack.push(*this);
63 }

References m_stateStack.

◆ refreshActionProperties()

void KisKXMLGUIFactoryPrivate::refreshActionProperties ( KisKXMLGUIClient * client,
const QList< QAction * > & actions,
const QDomDocument & doc )

Definition at line 339 of file kxmlguifactory.cpp.

340{
341 // These were used for applyShortcutScheme() but not for applyActionProperties()??
342 Q_UNUSED(client);
343 Q_UNUSED(actions);
344
345
346 // try to find and apply user-defined shortcuts
347 const QDomElement actionPropElement = findActionPropertiesElement(doc);
348 if (!actionPropElement.isNull()) {
349 applyActionProperties(actionPropElement);
350 }
351}
void applyActionProperties(const QDomElement &element, ShortcutOption shortcutOption=KisKXMLGUIFactoryPrivate::SetActiveShortcut)
static QDomElement findActionPropertiesElement(const QDomDocument &doc)

References applyActionProperties(), and findActionPropertiesElement().

◆ saveDefaultActionProperties()

void KisKXMLGUIFactoryPrivate::saveDefaultActionProperties ( const QList< QAction * > & actions)

Definition at line 353 of file kxmlguifactory.cpp.

354{
355 // This method is called every time the user activated a new
356 // kxmlguiclient. We only want to execute the following code only once in
357 // the lifetime of an action.
358 Q_FOREACH (QAction *action, actions) {
359 // Skip 0 actions or those we have seen already.
360 if (!action || action->property("_k_DefaultShortcut").isValid()) {
361 continue;
362 }
363
364 // Check if the default shortcut is set
365 QList<QKeySequence> defaultShortcut = action->property("defaultShortcuts").value<QList<QKeySequence> >();
366 QList<QKeySequence> activeShortcut = action->shortcuts();
367 //qDebug() << action->objectName() << "default=" << defaultShortcut.toString() << "active=" << activeShortcut.toString();
368
369 // Check if we have an empty default shortcut and an non empty
370 // custom shortcut. Print out a warning and correct the mistake.
371 if ((!activeShortcut.isEmpty()) && defaultShortcut.isEmpty()) {
372 action->setProperty("_k_DefaultShortcut", QVariant::fromValue(activeShortcut));
373 } else {
374 action->setProperty("_k_DefaultShortcut", QVariant::fromValue(defaultShortcut));
375 }
376 }
377}

Member Data Documentation

◆ attrName

QString KisKXMLGUIFactoryPrivate::attrName

Definition at line 104 of file kxmlguifactory.cpp.

◆ m_clients

QList<KisKXMLGUIClient *> KisKXMLGUIFactoryPrivate::m_clients

Definition at line 100 of file kxmlguifactory.cpp.

◆ m_containerName

QString KisKXMLGUIFactoryPrivate::m_containerName

Definition at line 95 of file kxmlguifactory.cpp.

◆ m_defaultMergingName

QString KisKXMLGUIFactoryPrivate::m_defaultMergingName

Definition at line 90 of file kxmlguifactory.cpp.

◆ m_rootNode

ContainerNode* KisKXMLGUIFactoryPrivate::m_rootNode

Definition at line 88 of file kxmlguifactory.cpp.

◆ m_stateStack

BuildStateStack KisKXMLGUIFactoryPrivate::m_stateStack

Definition at line 106 of file kxmlguifactory.cpp.

◆ tagActionList

QString KisKXMLGUIFactoryPrivate::tagActionList

Definition at line 102 of file kxmlguifactory.cpp.


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