quint32 module_id; quint32 message_status; QStringList m_; if(the_message_keeper->pop_message(module_id, message_status, m_)) { QTreeWidgetItem *the_m = new QTreeWidgetItem(); the_m->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); //date_time tm the_moment = to_tm(posix_time::second_clock::local_time()); QString qstr_time(QString("[%1.%2 %3:%4:%5]").arg(the_moment.tm_mday, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_mon + 1, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_hour, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_min, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_sec, 2, 10, QLatin1Char('0'))); the_m->setText(0, qstr_time); //message source icon the_m->setIcon(1, modules_icons[module_id ].get_icon()); //message type icon the_m->setIcon(2, message_types_icons[message_status].get_icon()); QStringList::const_iterator the_string = m_.begin(); //message 1st string the_m->setText(3, *the_string); //message other strings for(++the_string; the_string != m_.end(); ++the_string) { QTreeWidgetItem *current_child = new QTreeWidgetItem(); current_child->setText(3, *the_string); the_m->addChild(current_child); } //messages_from_topTV это и есть QTreeWidget messages_from_topTV->addTopLevelItem(the_m);
delete messages_from_topTV->TakeTopLevelItem(0);
QMetaObject::invokeMethod(messages_from_topTV, "takeTopLevelItem",Qt::QueuedConnection, Q_ARG(int, 0));
quint32 module_id; quint32 message_status; QStringList m_; if(the_message_keeper->pop_message(module_id, message_status, m_)) { //здесь уже messages_from_topTV это QTreeView message_model *model = reinterpret_cast<message_model*>(messages_from_topTV->model()); message_model_item *message_item = new message_model_item(); //date_time tm the_moment = to_tm(posix_time::second_clock::local_time()); QString qstr_time(QString("[%1.%2 %3:%4:%5]").arg(the_moment.tm_mon + 1, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_mday, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_hour, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_min, 2, 10, QLatin1Char('0')) .arg(the_moment.tm_sec, 2, 10, QLatin1Char('0'))); message_item->setItemTime(QVariant(qstr_time)); //message source icon message_item->setItemModuleIcon(QVariant(modules_icons[module_id].get_icon())); //message type icon message_item->setItemStatusIcon(QVariant(message_types_icons[message_status].get_icon())); QStringList::const_iterator the_string = m_.begin(); //message 1st string message_item->setItemMessage(QVariant(*the_string)); //message other strings for(++the_string; the_string != m_.end(); ++the_string) { message_model_item *current_child = new message_model_item(); current_child->setItemMessage(QVariant(*the_string)); message_item->insertChild(message_item->childCount(), current_child); } model->insertTopLevelRow(message_item); int item_count = model->topLevelItemCount(); if( item_count > count_lines) { model->removeRow(0); }
inline bool QAbstractItemModel::removeRow(int arow, const QModelIndex &aparent){ return removeRows(arow, 1, aparent); }
bool message_model::removeRows(int position, int rows, const QModelIndex &parent){ message_model_item *parentItem = getItem(parent); bool success = true; beginRemoveRows(parent, position, position + rows - 1); success = parentItem->removeChildren(position, rows); endRemoveRows(); return success;}