From 53f335f2bef2748a2fa26fa93594a7af32f83dbd Mon Sep 17 00:00:00 2001 From: Colin Ward Date: Fri, 29 Dec 2023 11:54:40 +1000 Subject: [PATCH] Addd CStdGadgetTree::setTitle() method This method allows the user to set the title of the gadget tree dynamically. --- Qt/QtGadgetTree.cpp | 2 +- Qt/QtGadgetTree.h | 5 +++++ StdGadgetTree.cpp | 28 ++++++++++++++++++++++++++++ StdGadgets.h | 2 ++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Qt/QtGadgetTree.cpp b/Qt/QtGadgetTree.cpp index 747e815..ef80aa5 100644 --- a/Qt/QtGadgetTree.cpp +++ b/Qt/QtGadgetTree.cpp @@ -15,7 +15,7 @@ void CQtTreeWidget::construct(const std::string &a_title) { /* Set some sensible default settings, such as the number of columns to display */ setColumnCount(1); - setHeaderLabels(QStringList(a_title.c_str())); + setHeaderLabel(a_title.c_str()); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); /* And connect the itemClicked() slot so that we are notified when an item is clicked */ diff --git a/Qt/QtGadgetTree.h b/Qt/QtGadgetTree.h index f695875..a01ab49 100644 --- a/Qt/QtGadgetTree.h +++ b/Qt/QtGadgetTree.h @@ -29,6 +29,11 @@ class CQtTreeWidget : public QTreeWidget void construct(const std::string &a_title); + void setTitle(const std::string &a_title) + { + setHeaderLabel(a_title.c_str()); + } + public slots: void itemClicked(); diff --git a/StdGadgetTree.cpp b/StdGadgetTree.cpp index 984fb89..3a21369 100644 --- a/StdGadgetTree.cpp +++ b/StdGadgetTree.cpp @@ -190,3 +190,31 @@ void CStdGadgetTree::setContent(StdList &a_items) #endif /* ! QT_GUI_LIB */ } + +/** + * Sets the title of the gadget tree. + * Sets or updates the title currently displayed in the gadget tree. + * + * @date Friday 29-Dec-2023 11:00 am, Code HQ @ Ashley's house + * @param a_title Title to be displayed at the top of the tree's column + */ + +void CStdGadgetTree::setTitle(const std::string &a_title) +{ + +#ifdef __amigaos__ + + /* For Amiga OS the title string is not copied by the native gadget, so we copy it into our own persistent memory */ + /* before assigning it to the tree */ + m_title = a_title; + g_columnInfo[0].ci_Title = (STRPTR) m_title.c_str(); + + SetGadgetAttrs((struct Gadget *) m_poGadget, NULL, NULL, LISTBROWSER_ColumnInfo, (ULONG) g_columnInfo, TAG_DONE); + +#elif defined(QT_GUI_LIB) + + m_tree.setTitle(a_title); + +#endif /* QT_GUI_LIB */ + +} diff --git a/StdGadgets.h b/StdGadgets.h index e8f2429..cf205df 100644 --- a/StdGadgets.h +++ b/StdGadgets.h @@ -445,6 +445,8 @@ class CStdGadgetTree : public CStdGadget std::string getSelectedItem(); void setContent(StdList &a_items); + + void setTitle(const std::string &a_title); }; /* Mixin class for the slider or proportional gadget to be able to notify its client */