0

I have many objects which contain different properties.

I'm trying to create a properties' editor dialog where I can pass the properties as a template and then, based on the template, construct different dialog panels for representing that specific object properties.

Unfortunately, mixing the virtual functions and templates is not supported.

How can I pass the object properties and then return modified set back in order to modify the object visual representation?

One solution could be to send the object ID and construct the panels based on it with a long switch statement. But it seems ugly.

To make it more complicated, the dialog that will show with the properties and the objects are in different libraries. I'm trying to separate the code and break the linkage whenever possible.

class A
{
private:
    std::string name, tag;
    font labelFont, textFont;
};

class B
{
private:
    std::string name, tag;
    color labelColor, textColor;
};

typedef template<type T> int CallDialog(window *parent, T &options, int objectType);

int CallDialog()
{
    MyDoalog dlg( parent, options, objectType );
    if( dlg.OK() )
    {
        if( objectType == 1 )
        {
            options.labelFont = dlg.GetLaelFont()
            options.textFnt = dlg.GetTextFont();
        }
    }
}

The function CallDialog() is in a different DLL (will be written by me), and I'm trying to avoid making multiple CallDialog()s passing all those properties depending on the object type.

17
  • 1
    Show your code, don't describe it in prose. Prepare a minimal reproducible example. Commented Dec 25, 2023 at 23:14
  • @IgorTandetnik, I don't have a code yet. Just merely trying to asses a good solution without doing code repetition... Commented Dec 25, 2023 at 23:20
  • 1
    Well, I for one am not sure what you mean by "properties", or by "pass the properties as a template". Show at least a sketch of what you envision the code that uses this machinery would look like. You seem to have a solution that involves code repetition or duplication - show an example of that. Commented Dec 25, 2023 at 23:23
  • @IgorTandetnik, I just tried to put some pseudo-code of what was talking about as possible solution. It is pseudo-code as I'm not sure it will compile and I'm sure it is highly unoptimal. Commented Dec 25, 2023 at 23:36
  • 2
    So, you already have some pre-defined piece of UI that collects two strings and two fonts, and another that collects two strings and two colors? And you just need to define a correspondence between A and B and those two UI pieces? To what extent do A and B expected to cooperate with this machinery? If nothing else, it's impossible to set private members of the class purely from outside, without some help from the class itself. Could A and B provide some kind of SaveToOptions and PopulateFromOptions methods? Commented Dec 26, 2023 at 1:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.