Pages
API Documentation
On this page

KWordMacroExpander Class

Abstract base class for simple word macro substitutors. More...

  • Header: #include <KMacroExpander>
  • CMake: find_package(KF6 REQUIRED COMPONENTS CoreAddons)
    target_link_libraries(mytarget PRIVATE KF6::CoreAddons)
  • Inherits: KMacroExpanderBase

List of all members, including inherited members

Public Functions

Protected Functions

Detailed Description

Use this instead of the functions in the KMacroExpander namespace if speculatively pre-filling the substitution map would be too expensive.

A typical application:

class MyClass {
...
  private:
    QString m_str;
...
  friend class MyExpander;
};

class MyExpander : public KWordMacroExpander {
  public:
    MyExpander( MyClass *_that ) : KWordMacroExpander(), that( _that ) {}
  protected:
    virtual bool expandMacro( const QString &str, QStringList &ret );
  private:
    MyClass *that;
};

bool MyExpander::expandMacro( const QString &str, QStringList &ret )
{
  if (str == "macro") {
    ret += complexOperation( that->m_str );
    return true;
  }
  return false;
}

... MyClass::...(...)
{
  QString str;
  ...
  MyExpander mx( this );
  mx.expandMacrosShellQuote( str );
  ...
}

Alternatively MyClass could inherit from KWordMacroExpander directly.

Member Function Documentation

[explicit] KWordMacroExpander::KWordMacroExpander(QChar c = QLatin1Char('%'))

Constructor.

c escape char indicating start of macros, or QChar::null for none

[pure virtual protected] bool KWordMacroExpander::expandMacro(const QString &str, QStringList &ret)

Return substitution list ret for string macro str.

str the macro to expand

ret return variable reference. It is guaranteed to be empty when expandMacro is entered.

Returns true iff str was a recognized macro name

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.