VirtualBox

Changeset 81476 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 23, 2019 8:13:40 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Removing a persistent pointer to a container element. was not a very bright idea.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r81456 r81476  
    617617    void loadLayouts();
    618618
    619     void setCurrentLayout(const QString &strLayoutName);
    620619    void setCurrentLayout(const QUuid &layoutUid);
    621620    UISoftKeyboardLayout *currentLayout();
     
    656655    void parentDialogDeactivated();
    657656    bool isColorThemeEditable() const;
    658 
     657    /** Returns a list of layout names that have been edited but not yet saved to a file. */
    659658    QStringList unsavedLayoutsNameList() const;
    660659
     
    687686    /** Sets m_pKeyBeingEdited. */
    688687    void               setKeyBeingEdited(UISoftKeyboardKey *pKey);
    689     void               setCurrentLayout(UISoftKeyboardLayout *pLayout);
    690     UISoftKeyboardLayout *findLayoutByName(const QString &strName);
    691     UISoftKeyboardLayout *findLayoutByUid(const QUuid &uid);
     688    bool               layoutByNameExists(const QString &strName) const;
     689
    692690    /** Looks under the default keyboard layout folder and add the file names to the fileList. */
    693691    void               lookAtDefaultLayoutFolder(QStringList &fileList);
     
    703701    QVector<UISoftKeyboardKey*> m_pressedModifiers;
    704702    QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts;
    705     UISoftKeyboardPhysicalLayout          m_numPadLayout;
    706     UISoftKeyboardPhysicalLayout          m_multiMediaKeysLayout;
    707     QVector<UISoftKeyboardLayout>         m_layouts;
    708     UISoftKeyboardLayout *m_pCurrentKeyboardLayout;
     703    UISoftKeyboardPhysicalLayout       m_numPadLayout;
     704    UISoftKeyboardPhysicalLayout       m_multiMediaKeysLayout;
     705    QMap<QUuid, UISoftKeyboardLayout>  m_layouts;
     706    QUuid                              m_uCurrentLayoutId;
    709707    /** Key is the key position as read from the layout and value is the message we show as mouse hovers over the key. */
    710708    QMap<int, QString> m_keyTooltips;
     
    21332131    , m_pKeyPressed(0)
    21342132    , m_currentColorTheme(0)
    2135     , m_pCurrentKeyboardLayout(0)
    21362133    , m_iInitialHeight(0)
    21372134    , m_iInitialWidth(0)
     
    21682165{
    21692166    Q_UNUSED(pEvent);
    2170     if (!m_pCurrentKeyboardLayout || m_iInitialWidth == 0 || m_iInitialWidthNoNumPad == 0 || m_iInitialHeight == 0)
     2167    if (!m_layouts.contains(m_uCurrentLayoutId))
     2168        return;
     2169
     2170    UISoftKeyboardLayout &currentLayout = m_layouts[m_uCurrentLayoutId];
     2171
     2172    if (m_iInitialWidth == 0 || m_iInitialWidthNoNumPad == 0 || m_iInitialHeight == 0)
    21712173        return;
    21722174
     
    21922194    float fLedMargin =  0.6 * unitSize;
    21932195
    2194     UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid());
     2196    UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid());
    21952197    if (!pPhysicalLayout)
    21962198        return;
     
    22322234            painter.drawPolygon(key.polygon());
    22332235
    2234             m_pCurrentKeyboardLayout->drawTextInRect(key, painter);
     2236            currentLayout.drawTextInRect(key, painter);
    22352237            /* Draw small LED like circles on the modifier/lock keys: */
    22362238            if (key.type() != KeyType_Ordinary)
     
    23392341void UISoftKeyboardWidget::saveCurentLayoutToFile()
    23402342{
    2341     if (!m_pCurrentKeyboardLayout)
    2342         return;
    2343 
     2343    if (!m_layouts.contains(m_uCurrentLayoutId))
     2344        return;
     2345    UISoftKeyboardLayout &currentLayout = m_layouts[m_uCurrentLayoutId];
    23442346    QString strHomeFolder = uiCommon().homeFolder();
    23452347    QDir dir(strHomeFolder);
     
    23582360    dialog.setWindowModality(Qt::WindowModal);
    23592361    dialog.setWindowTitle(UISoftKeyboard::tr("Provide a file name"));
    2360     dialog.setTextValue(m_pCurrentKeyboardLayout->name());
     2362    dialog.setTextValue(currentLayout.name());
    23612363    dialog.setLabelText(QString("%1 %2").arg(UISoftKeyboard::tr("The file will be saved under:\n")).arg(strHomeFolder));
    23622364    if (dialog.exec() == QDialog::Rejected)
     
    23692371    }
    23702372
    2371     UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid());
     2373    UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid());
    23722374    if (!pPhysicalLayout)
    23732375    {
     
    23932395    xmlWriter.writeStartDocument("1.0");
    23942396    xmlWriter.writeStartElement("layout");
    2395     xmlWriter.writeTextElement("name", m_pCurrentKeyboardLayout->name());
    2396     xmlWriter.writeTextElement("nativename", m_pCurrentKeyboardLayout->nativeName());
     2397    xmlWriter.writeTextElement("name", currentLayout.name());
     2398    xmlWriter.writeTextElement("nativename", currentLayout.nativeName());
    23972399    xmlWriter.writeTextElement("physicallayoutid", pPhysicalLayout->uid().toString());
    2398     xmlWriter.writeTextElement("id", m_pCurrentKeyboardLayout->uid().toString());
     2400    xmlWriter.writeTextElement("id", currentLayout.uid().toString());
    23992401
    24002402    QVector<UISoftKeyboardRow> &rows = pPhysicalLayout->rows();
     
    24092411           UISoftKeyboardKey &key = keys[j];
    24102412           xmlWriter.writeTextElement("position", QString::number(key.position()));
    2411            xmlWriter.writeTextElement("basecaption", m_pCurrentKeyboardLayout->baseCaption(key.position()));
    2412            xmlWriter.writeTextElement("shiftcaption", m_pCurrentKeyboardLayout->shiftCaption(key.position()));
    2413            xmlWriter.writeTextElement("altgrcaption", m_pCurrentKeyboardLayout->altGrCaption(key.position()));
    2414            xmlWriter.writeTextElement("shiftaltgrcaption", m_pCurrentKeyboardLayout->shiftAltGrCaption(key.position()));
     2413           xmlWriter.writeTextElement("basecaption", currentLayout.baseCaption(key.position()));
     2414           xmlWriter.writeTextElement("shiftcaption", currentLayout.shiftCaption(key.position()));
     2415           xmlWriter.writeTextElement("altgrcaption", currentLayout.altGrCaption(key.position()));
     2416           xmlWriter.writeTextElement("shiftaltgrcaption", currentLayout.shiftAltGrCaption(key.position()));
    24152417           xmlWriter.writeEndElement();
    24162418       }
     
    24202422
    24212423   xmlFile.close();
    2422    m_pCurrentKeyboardLayout->setSourceFilePath(strFileName);
    2423    m_pCurrentKeyboardLayout->setEditedBuNotSaved(false);
     2424   currentLayout.setSourceFilePath(strFileName);
     2425   currentLayout.setEditedBuNotSaved(false);
    24242426   sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is saved")));
    24252427}
     
    24272429void UISoftKeyboardWidget::copyCurentLayout()
    24282430{
    2429 
    2430     UISoftKeyboardLayout newLayout(*(m_pCurrentKeyboardLayout));
     2431    UISoftKeyboardLayout newLayout(m_layouts[m_uCurrentLayoutId]);
    24312432
    24322433    QString strNewName = QString("%1-%2").arg(newLayout.name()).arg(UISoftKeyboard::tr("Copy"));
    24332434    int iCount = 1;
    2434     while (findLayoutByName(strNewName))
     2435    while (layoutByNameExists(strNewName))
    24352436    {
    24362437        strNewName = QString("%1-%2-%3").arg(newLayout.name()).arg(UISoftKeyboard::tr("Copy")).arg(QString::number(iCount));
     
    25882589}
    25892590
    2590 
    25912591void UISoftKeyboardWidget::deleteCurrentLayout()
    25922592{
    2593     if (!m_pCurrentKeyboardLayout || !m_pCurrentKeyboardLayout->editable() || m_pCurrentKeyboardLayout->isFromResources())
    2594         return;
    2595     /* Make sure we have at least one layout. */
     2593    if (!m_layouts.contains(m_uCurrentLayoutId))
     2594        return;
     2595
     2596    /* Make sure we will have at least one layout remaining. */
    25962597    if (m_layouts.size() <= 1)
    25972598        return;
    25982599
    2599     int iIndex = m_layouts.indexOf(*(m_pCurrentKeyboardLayout));
    2600     if (iIndex == -1)
    2601         return;
     2600    const UISoftKeyboardLayout &layout = m_layouts.value(m_uCurrentLayoutId);
     2601    if (!layout.editable() || layout.isFromResources())
     2602        return;
     2603
     2604    m_layouts.remove(m_uCurrentLayoutId);
     2605    setCurrentLayout(m_layouts.firstKey());
    26022606
    26032607    QDir fileToDelete;
    2604     QString strFilePath(m_pCurrentKeyboardLayout->sourceFilePath());
     2608    QString strFilePath(layout.sourceFilePath());
     2609
    26052610    bool fFileExists = false;
    26062611    if (!strFilePath.isEmpty())
    26072612        fFileExists = fileToDelete.exists(strFilePath);
    2608 
     2613    /* It might be that the layout copied but not yet saved into a file: */
    26092614    if (fFileExists)
    26102615    {
     
    26162621                                        false /* ok button by default? */))
    26172622            return;
    2618     }
    2619 
    2620     m_layouts.removeAt(iIndex);
    2621     setCurrentLayout(&(m_layouts[0]));
    2622     /* It might be that the layout copied but not yet saved into a file: */
    2623     if (fFileExists)
    2624     {
     2623
    26252624        if (fileToDelete.remove(strFilePath))
    26262625            sigStatusBarMessage(QString("%1 %2 %3").arg(UISoftKeyboard::tr("The file ")).arg(strFilePath).arg(UISoftKeyboard::tr(" has been deleted")));
     
    26442643void UISoftKeyboardWidget::addLayout(const UISoftKeyboardLayout &newLayout)
    26452644{
    2646     m_layouts.append(newLayout);
     2645    if (m_layouts.contains(newLayout.uid()))
     2646        return;
     2647    m_layouts[newLayout.uid()] = newLayout;
    26472648}
    26482649
     
    26672668UISoftKeyboardKey *UISoftKeyboardWidget::keyUnderMouse(const QPoint &eventPosition)
    26682669{
    2669     if (!m_pCurrentKeyboardLayout)
    2670         return 0;
    2671     UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid());
     2670    const UISoftKeyboardLayout &currentLayout = m_layouts.value(m_uCurrentLayoutId);
     2671
     2672    UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid());
    26722673    if (!pPhysicalLayout)
    26732674        return 0;
     
    28132814}
    28142815
    2815 void UISoftKeyboardWidget::setCurrentLayout(const QString &strLayoutName)
    2816 {
    2817     UISoftKeyboardLayout *pLayout = findLayoutByName(strLayoutName);
    2818     if (!pLayout)
    2819         return;
    2820     setCurrentLayout(pLayout);
    2821 }
    2822 
    28232816void UISoftKeyboardWidget::setCurrentLayout(const QUuid &layoutUid)
    28242817{
    2825     UISoftKeyboardLayout *pLayout = findLayoutByUid(layoutUid);
    2826     if (!pLayout)
    2827         return;
    2828     setCurrentLayout(pLayout);
     2818    if (m_uCurrentLayoutId == layoutUid || !m_layouts.contains(layoutUid))
     2819        return;
     2820
     2821    UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_layouts[layoutUid].physicalLayoutUuid());
     2822    if (!pPhysicalLayout)
     2823        return;
     2824
     2825    m_uCurrentLayoutId = layoutUid;
     2826    emit sigCurrentLayoutChange();
     2827    update();
    28292828}
    28302829
    28312830UISoftKeyboardLayout *UISoftKeyboardWidget::currentLayout()
    28322831{
    2833     return m_pCurrentKeyboardLayout;
     2832    if (!m_layouts.contains(m_uCurrentLayoutId))
     2833        return 0;
     2834    return &(m_layouts[m_uCurrentLayoutId]);
    28342835}
    28352836
     
    30263027        loadKeyboardLayout(strName);
    30273028    /* Mark the layouts we load from the resources as non-editable: */
    3028     for (int i = 0; i < m_layouts.size(); ++i)
    3029     {
    3030         m_layouts[i].setEditable(false);
    3031         m_layouts[i].setIsFromResources(true);
     3029    for (QMap<QUuid, UISoftKeyboardLayout>::iterator iterator = m_layouts.begin(); iterator != m_layouts.end(); ++iterator)
     3030    {
     3031        iterator.value().setEditable(false);
     3032        iterator.value().setIsFromResources(true);
    30323033    }
    30333034    keyboardLayoutNames.clear();
     
    30393040    if (m_layouts.isEmpty())
    30403041        return;
    3041     for (int i = 0; i < m_layouts.size(); ++i)
    3042         m_layouts[i].setEditedBuNotSaved(false);
    3043     setCurrentLayout(&(m_layouts[0]));
     3042    for (QMap<QUuid, UISoftKeyboardLayout>::iterator iterator = m_layouts.begin(); iterator != m_layouts.end(); ++iterator)
     3043        iterator.value().setEditedBuNotSaved(false);
     3044    setCurrentLayout(m_layouts.firstKey());
    30443045}
    30453046
     
    30783079}
    30793080
    3080 void UISoftKeyboardWidget::setCurrentLayout(UISoftKeyboardLayout *pLayout)
    3081 {
    3082     if (m_pCurrentKeyboardLayout == pLayout)
    3083         return;
    3084     m_pCurrentKeyboardLayout = pLayout;
    3085     if (!m_pCurrentKeyboardLayout)
    3086     {
    3087         emit sigCurrentLayoutChange();
    3088         return;
    3089     }
    3090     emit sigCurrentLayoutChange();
    3091 
    3092     UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid());
    3093     if (!pPhysicalLayout)
    3094         return;
    3095 
    3096     update();
    3097 }
    3098 
    3099 UISoftKeyboardLayout *UISoftKeyboardWidget::findLayoutByName(const QString &strName)
    3100 {
    3101     for (int i = 0; i < m_layouts.size(); ++i)
    3102     {
    3103         if (m_layouts[i].name() == strName)
    3104             return &(m_layouts[i]);
    3105     }
    3106     return 0;
    3107 }
    3108 
    3109 UISoftKeyboardLayout *UISoftKeyboardWidget::findLayoutByUid(const QUuid &uid)
    3110 {
    3111     if (uid.isNull())
    3112         return 0;
    3113     for (int i = 0; i < m_layouts.size(); ++i)
    3114     {
    3115         if (m_layouts[i].uid() == uid)
    3116             return &(m_layouts[i]);
    3117     }
    3118     return 0;
     3081bool UISoftKeyboardWidget::layoutByNameExists(const QString &strName) const
     3082{
     3083    foreach (const UISoftKeyboardLayout &layout, m_layouts)
     3084    {
     3085        if (layout.name() == strName)
     3086            return true;
     3087    }
     3088    return false;
    31193089}
    31203090
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