tdf#130857 VclBuilder: Store radio button groups in BuilderBase

Move the std::vector<RadioButtonGroupMap> and the method
to extract and add to that map from VclBuilder to its base
class, BuilderBase.

Add a getter, BuilderBase::getRadioButtonGroupMaps instead
of accessing the base class member directly in the VclBuilder subclass.

Change-Id: Ic0d2abbd9faa41760d542ab22a80f2ba23136ccf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178442
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn 2024-12-13 22:11:34 +01:00
parent ae07889111
commit ce67331daa
3 changed files with 14 additions and 9 deletions

View File

@ -127,8 +127,6 @@ private:
};
std::vector<WinAndId> m_aChildren;
typedef StringPair RadioButtonGroupMap;
struct ButtonImageWidgetMap
{
OUString m_sID;
@ -179,8 +177,6 @@ private:
struct VclParserState
{
std::vector<RadioButtonGroupMap> m_aGroupMaps;
std::vector<ComboBoxModelMap> m_aModelMaps;
std::vector<TextBufferMap> m_aTextBufferMaps;
@ -254,7 +250,6 @@ private:
static int getImageSize(const stringmap &rMap);
void extractGroup(const OUString &id, stringmap &rVec);
void extractModel(const OUString &id, stringmap &rVec);
void extractBuffer(const OUString &id, stringmap &rVec);
static bool extractAdjustmentToMap(const OUString &id, stringmap &rVec, std::vector<WidgetAdjustmentMap>& rAdjustmentMap);

View File

@ -77,6 +77,7 @@ protected:
};
typedef StringPair MnemonicWidgetMap;
typedef StringPair RadioButtonGroupMap;
static void collectPangoAttribute(xmlreader::XmlReader& reader, stringmap& rMap);
static void collectAtkRelationAttribute(xmlreader::XmlReader& reader, stringmap& rMap);
@ -112,6 +113,9 @@ protected:
void extractMnemonicWidget(const OUString& id, stringmap& rMap);
const std::vector<MnemonicWidgetMap>& getMnemonicWidgetMaps() const;
void extractRadioButtonGroup(const OUString& id, stringmap& rVec);
const std::vector<RadioButtonGroupMap>& getRadioButtonGroupMaps() const;
OUString finalizeValue(const OString& rContext, const OString& rValue,
const bool bTranslate) const;
@ -149,6 +153,7 @@ private:
std::map<OUString, TextBuffer> m_aTextBuffers;
std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps;
std::vector<RadioButtonGroupMap> m_aRadioButtonGroupMaps;
};
std::unique_ptr<ParserState> m_pParserState;

View File

@ -481,6 +481,11 @@ const std::vector<BuilderBase::MnemonicWidgetMap>& BuilderBase::getMnemonicWidge
return m_pParserState->m_aMnemonicWidgetMaps;
}
const std::vector<BuilderBase::RadioButtonGroupMap>& BuilderBase::getRadioButtonGroupMaps() const {
assert(m_pParserState && "parser state no more valid");
return m_pParserState->m_aRadioButtonGroupMaps;
}
OUString BuilderBase::finalizeValue(const OString& rContext, const OString& rValue,
const bool bTranslate) const
{
@ -554,7 +559,7 @@ VclBuilder::VclBuilder(vcl::Window* pParent, std::u16string_view sUIDir, const O
}
//Set radiobutton groups when everything has been imported
for (auto const& elem : m_pVclParserState->m_aGroupMaps)
for (auto const& elem : getRadioButtonGroupMaps())
{
RadioButton *pOne = get<RadioButton>(elem.m_sID);
RadioButton *pOther = get<RadioButton>(elem.m_sValue);
@ -1098,7 +1103,7 @@ namespace
}
}
void VclBuilder::extractGroup(const OUString &id, stringmap &rMap)
void BuilderBase::extractRadioButtonGroup(const OUString &id, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(u"group"_ustr);
if (aFind != rMap.end())
@ -1107,7 +1112,7 @@ void VclBuilder::extractGroup(const OUString &id, stringmap &rMap)
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
sID = sID.copy(0, nDelim);
m_pVclParserState->m_aGroupMaps.emplace_back(id, sID);
m_pParserState->m_aRadioButtonGroupMaps.emplace_back(id, sID);
rMap.erase(aFind);
}
}
@ -1603,7 +1608,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString
}
else if (name == "GtkRadioButton")
{
extractGroup(id, rMap);
extractRadioButtonGroup(id, rMap);
WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK;
VclPtr<RadioButton> xButton = VclPtr<RadioButton>::Create(pParent, true, nBits);
xButton->SetImageAlign(ImageAlign::Left); //default to left