VirtualBox

Changeset 72167 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 8, 2018 4:24:47 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Large cleanup for UIRichTextString and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r72166 r72167  
    10121012        src/medium/UIMediumDetailsWidget.cpp \
    10131013        src/medium/UIMediumManager.cpp \
    1014         src/objects/UIRichTextString.cpp \
    10151014        src/runtime/UIConsoleEventHandler.cpp \
    10161015        src/runtime/UIFrameBuffer.cpp \
     
    12351234        src/medium/UIMediumDefs.cpp \
    12361235        src/medium/UIMediumEnumerator.cpp \
     1236        src/objects/UIRichTextString.cpp \
    12371237        src/runtime/UIActionPoolRuntime.cpp \
    12381238        src/selector/UIActionPoolSelector.cpp \
     
    14121412        src/medium/UIMediumDefs.cpp \
    14131413        src/medium/UIMediumEnumerator.cpp \
     1414        src/objects/UIRichTextString.cpp \
    14141415        src/runtime/UIActionPoolRuntime.cpp \
    14151416        src/selector/UIActionPoolSelector.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/objects/UIRichTextString.cpp

    r69500 r72167  
    55
    66/*
    7  * Copyright (C) 2015-2017 Oracle Corporation
     7 * Copyright (C) 2015-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3333
    34 const QString UIRichTextString::m_sstrAny = QString("[\\s\\S]*");
    35 const QMap<UIRichTextString::Type, QString> UIRichTextString::m_sPatterns = populatePatterns();
    36 const QMap<UIRichTextString::Type, bool> UIRichTextString::m_sPatternHasMeta = populatePatternHasMeta();
    37 
    38 UIRichTextString::UIRichTextString(Type type /* = Type_None */)
    39     : m_type(type)
     34
     35const QString UIRichTextString::s_strAny = QString("[\\s\\S]*");
     36const QMap<UIRichTextString::Type, QString> UIRichTextString::s_patterns = populatePatterns();
     37const QMap<UIRichTextString::Type, bool> UIRichTextString::s_doPatternHasMeta = populatePatternHasMeta();
     38
     39UIRichTextString::UIRichTextString(Type enmType /* = Type_None */)
     40    : m_enmType(enmType)
    4041    , m_strString(QString())
    4142    , m_strStringMeta(QString())
     
    4344}
    4445
    45 UIRichTextString::UIRichTextString(const QString &strString, Type type /* = Type_None */, const QString &strStringMeta /* = QString() */)
    46     : m_type(type)
     46UIRichTextString::UIRichTextString(const QString &strString, Type enmType /* = Type_None */, const QString &strStringMeta /* = QString() */)
     47    : m_enmType(enmType)
    4748    , m_strString(strString)
    4849    , m_strStringMeta(strStringMeta)
     
    8283    range.start = iShift;
    8384    range.length = toString().size();
    84     range.format = textCharFormat(m_type);
     85    range.format = textCharFormat(m_enmType);
    8586    /* Enable anchor if present: */
    8687    if (!m_strAnchor.isNull())
     
    120121
    121122    /* Parse the passed QString with all the known patterns: */
    122     foreach (const Type &enmPattern, m_sPatterns.keys())
     123    foreach (const Type &enmPattern, s_patterns.keys())
    123124    {
    124125        /* Get the current pattern: */
    125         const QString strPattern = m_sPatterns.value(enmPattern);
     126        const QString strPattern = s_patterns.value(enmPattern);
    126127
    127128        /* Recursively parse the string: */
     
    148149                    m_strString.remove(iPosition, regExp.cap(0).size());
    149150                    /* And paste that string as our child: */
    150                     const bool fPatterHasMeta = m_sPatternHasMeta.value(enmPattern);
     151                    const bool fPatterHasMeta = s_doPatternHasMeta.value(enmPattern);
    151152                    const QString strSubString = !fPatterHasMeta ? regExp.cap(1) : regExp.cap(2);
    152153                    const QString strSubMeta   = !fPatterHasMeta ? QString()     : regExp.cap(1);
     
    183184                                        const QString &strCurrentPattern, int iCurrentLevel /* = 0 */)
    184185{
    185     QRegExp regExp(strCurrentPattern.arg(m_sstrAny));
     186    QRegExp regExp(strCurrentPattern.arg(s_strAny));
    186187    regExp.setMinimal(true);
    187188    if (regExp.indexIn(strString) != -1)
    188189        return searchForMaxLevel(strString, strPattern,
    189                                  strCurrentPattern.arg(m_sstrAny + strPattern + m_sstrAny),
     190                                 strCurrentPattern.arg(s_strAny + strPattern + s_strAny),
    190191                                 iCurrentLevel + 1);
    191192    return iCurrentLevel;
     
    198199    if (iCurrentLevel > 1)
    199200        return composeFullPattern(strPattern,
    200                                   strCurrentPattern.arg(m_sstrAny + strPattern + m_sstrAny),
     201                                  strCurrentPattern.arg(s_strAny + strPattern + s_strAny),
    201202                                  iCurrentLevel - 1);
    202     return strCurrentPattern.arg(m_sstrAny);
    203 }
    204 
    205 /* static */
    206 QTextCharFormat UIRichTextString::textCharFormat(Type type)
     203    return strCurrentPattern.arg(s_strAny);
     204}
     205
     206/* static */
     207QTextCharFormat UIRichTextString::textCharFormat(Type enmType)
    207208{
    208209    QTextCharFormat format;
    209     switch (type)
     210    switch (enmType)
    210211    {
    211212        case Type_Anchor:
     
    233234    return format;
    234235}
    235 
  • trunk/src/VBox/Frontends/VirtualBox/src/objects/UIRichTextString.h

    r69500 r72167  
    55
    66/*
    7  * Copyright (C) 2015-2017 Oracle Corporation
     7 * Copyright (C) 2015-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222#include <QTextLayout>
    2323
     24/* GUI includes: */
     25#include "UILibraryDefs.h"
     26
    2427/** Rich text string implementation which parses the passed QString
    2528  * and holds it as the tree of the formatted rich text blocks. */
    26 class UIRichTextString
     29class SHARED_LIBRARY_STUFF UIRichTextString
    2730{
    2831public:
     
    3740    };
    3841
    39     /** Default (empty) constructor. */
    40     UIRichTextString(Type type = Type_None);
     42    /** Constructs empty rich text string.
     43      * @param  enmType        Brings the type of <i>this</i> rich text block. */
     44    UIRichTextString(Type enmType = Type_None);
    4145
    42     /** Constructor taking passed QString.
    43       * @param strString     holds the string being parsed and held as the tree of rich text blocks,
    44       * @param type          holds the type of <i>this</i> rich text block,
    45       * @param strStringMeta holds the string containing meta data describing <i>this</i> rich text block. */
    46     UIRichTextString(const QString &strString, Type type = Type_None, const QString &strStringMeta = QString());
     46    /** Constructs rich text string.
     47      * @param  strString      Brings the string being parsed and held as the tree of rich text blocks.
     48      * @param  enmType        Brings the type of <i>this</i> rich text block.
     49      * @param  strStringMeta  Brings the string containing meta data describing <i>this</i> rich text block. */
     50    UIRichTextString(const QString &strString, Type enmType = Type_None, const QString &strStringMeta = QString());
    4751
    48     /** Destructor. */
    49     ~UIRichTextString();
     52    /** Destructor rich text string. */
     53    virtual ~UIRichTextString() /* override */;
    5054
    5155    /** Returns the QString representation. */
     
    5357
    5458    /** Returns the list of existing format ranges appropriate for QTextLayout.
    55       * @param iShift holds the shift of <i>this</i> rich text block accordig to it's root. */
     59      * @param  iShift  Brings the shift of <i>this</i> rich text block accordig to it's root. */
    5660    QList<QTextLayout::FormatRange> formatRanges(int iShift = 0) const;
    5761
     
    6569
    6670    /** Used to populate const static map of known patterns.
    67       * @note Keep it sync with the method below - #populatePatternHasMeta(). */
     71      * @note  Keep it sync with the method below - #populatePatternHasMeta(). */
    6872    static QMap<Type, QString> populatePatterns();
    6973    /** Used to populate const static map of meta flags for the known patterns.
    70       * @note Keep it sync with the method above - #populatePatterns(). */
     74      * @note  Keep it sync with the method above - #populatePatterns(). */
    7175    static QMap<Type, bool> populatePatternHasMeta();
    7276
    7377    /** Recursively searching for the maximum level of the passed pattern.
    74       * @param strString         holds the string to check for the current (recursively advanced) pattern in,
    75       * @param strPattern        holds the etalon pattern to recursively advance the current pattern with,
    76       * @param strCurrentPattern holds the current (recursively advanced) pattern to check for the presence of,
    77       * @param iCurrentLevel     holds the current level of the recursively advanced pattern. */
     78      * @param  strString          Brings the string to check for the current (recursively advanced) pattern in,
     79      * @param  strPattern         Brings the etalon pattern to recursively advance the current pattern with,
     80      * @param  strCurrentPattern  Brings the current (recursively advanced) pattern to check for the presence of,
     81      * @param  iCurrentLevel      Brings the current level of the recursively advanced pattern. */
    7882    static int searchForMaxLevel(const QString &strString, const QString &strPattern,
    7983                                 const QString &strCurrentPattern, int iCurrentLevel = 0);
    8084
    8185    /** Recursively composing the pattern of the maximum level.
    82       * @param strPattern        holds the etalon pattern to recursively update the current pattern with,
    83       * @param strCurrentPattern holds the current (recursively advanced) pattern,
    84       * @param iCurrentLevel     holds the amount of the levels left to recursively advance current pattern. */
     86      * @param  strPattern         Brings the etalon pattern to recursively update the current pattern with,
     87      * @param  strCurrentPattern  Brings the current (recursively advanced) pattern,
     88      * @param  iCurrentLevel      Brings the amount of the levels left to recursively advance current pattern. */
    8589    static QString composeFullPattern(const QString &strPattern,
    8690                                      const QString &strCurrentPattern, int iCurrentLevel);
    8791
    88     /** Composes the QTextCharFormat correpoding to passed @a type. */
    89     static QTextCharFormat textCharFormat(Type type);
     92    /** Composes the QTextCharFormat correpoding to passed @a enmType. */
     93    static QTextCharFormat textCharFormat(Type enmType);
    9094
    9195    /** Holds the type of <i>this</i> rich text block. */
    92     Type m_type;
     96    Type                          m_enmType;
    9397    /** Holds the string of <i>this</i> rich text block. */
    94     QString m_strString;
     98    QString                       m_strString;
    9599    /** Holds the string meta data of <i>this</i> rich text block. */
    96     QString m_strStringMeta;
     100    QString                       m_strStringMeta;
    97101    /** Holds the children of <i>this</i> rich text block. */
    98     QMap<int, UIRichTextString*> m_strings;
     102    QMap<int, UIRichTextString*>  m_strings;
    99103
    100104    /** Holds the anchor of <i>this</i> rich text block. */
    101     QString m_strAnchor;
     105    QString  m_strAnchor;
    102106    /** Holds the anchor to highlight in <i>this</i> rich text block and in it's children. */
    103     QString m_strHoveredAnchor;
     107    QString  m_strHoveredAnchor;
    104108
    105109    /** Holds the <i>any</i> string pattern. */
    106     static const QString m_sstrAny;
     110    static const QString              s_strAny;
    107111    /** Holds the map of known patterns. */
    108     static const QMap<Type, QString> m_sPatterns;
     112    static const QMap<Type, QString>  s_patterns;
    109113    /** Holds the map of meta flags for the known patterns. */
    110     static const QMap<Type, bool> m_sPatternHasMeta;
     114    static const QMap<Type, bool>     s_doPatternHasMeta;
    111115};
    112116
    113117#endif /* !___UIRichTextString_h___ */
    114 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette