Answer the question
In order to leave comments, you need to log in
How to come up with an additional table of virtual methods?
We have such a code. I greatly simplify, but still I'm talking about architecture, and not about compilability, right?
enum class ObjType { GROUP, LEAF };
class Obj {
public:
virtual ObjType type() const = 0;
virtual size_t nChildren() const = 0;
virtual std::shared_ptr<Obj> child(size_t i) = 0;
virtual QString tableData(int column, int role) = 0;
};
class Group : public Obj { … };
class Leaf : public Obj { … };
void MyModel::data(const QModelIndex& index, int role) {
Obj* obj = toObj(index);
switch (obj->type()) {
case ObjType::GROUP: {
// Куча всякой дряни с qobject_cast, switch(role), switch(index.column())
}
case ObjType::LEAF: {
// Такая же дрянь
}
}
}
Answer the question
In order to leave comments, you need to log in
your Obj is a DTO object passing the data loaded by the OD from the database to the Widget/View for display
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question