У меня есть объект:Добавить ребенка обычая QStandardItem
class Mando : public QObject, public QStandardItem {
Q_OBJECT
public:
std::string getDescription() const;
std::string getName() const;
explicit Mando(boost::filesystem::path filen);
private:
boost::filesystem::path file;
};
Q_DECLARE_METATYPE(Mando *)
Mando::Mando(boost::filesystem::path filen) {
file= filen; }
std::string Mando::getName() const {
return file.filename().string(); }
std::string Mando::getDescription() const {
return std::string("XxxxX"); }
И модель реализации:
ContentModel::ContentModel() : QStandardItemModel() {
QStringList headers;
headers << tr("Name") << tr("Description");
setHorizontalHeaderLabels(headers);
setColumnCount(headers.count()); }
QVariant ContentModel::data(const QModelIndex &index, int role) const {
if(role == Qt::DisplayRole)
switch(index.column()) {
case 0: return static_cast<Mando*>(item(index.row()))->getName().c_str();
case 1: return static_cast<Mando*>(item(index.row()))->getDescription().c_str(); }
return QStandardItemModel::data(index, role); }
добавить объекты, как это:
model->appendRow(new Mando(boost::filesystem::path("/home/user/riri.ini")));
model->appendRow(new Mando(boost::filesystem::path("/home/user/fifi.ini")));
model->appendRow(new Mando(boost::filesystem::path("/home/user/loulou.ini")));
view= new QTreeView();
view.setModel(model);
Все отлично работает, я получаю :
riri.ini XxxxX
fifi.ini XxxxX
loulou.ini XxxxX
Но в некоторых случаях мне нужно добавить одного ребенка.
riri.ini XxxxX
-> riri's child YyyyY
fifi.ini XxxxX
loulou.ini XxxxX
-> loulou's child YyyyY
Если добавить простую строку в тех случаях, Mando, как это:
Mando::Mando(boost::filesystem::path filen) {
file= filen;
appendRow(new QStandardItem() /* or */ QList<QStandardItem*>); }
Как отличить отца ребенка в ContentModel :: данные?