void Model::update(std::vector<Type> &fresh){ int prvsz = store.size(); int cursz = fresh.size(); beginInsertRows(QModelIndex(), prvsz, cursz); store.swap(fresh); endInsertRows();}
C++ (Qt) void Model::upDate(std::vector<typedata> &fresh, QTreeview *view){ int prvsz = v.size(); int cursz = fresh.size(); int count = cursz - prvsz; if (count>0) { beginInsertRows(QModelIndex(), prvsz, cursz - 1); v.swap(fresh); endInsertRows(); } else if(count==0){ QRect viewportRect = view->viewport()->rect(); QModelIndex topLeft = view->indexAt(viewportRect.topLeft()); QModelIndex bottomRight = view->indexAt(viewportRect.bottomRight()); if(topLeft.isValid() && bottomRight.isValid()){ dataChanged(topLeft,bottomRight); } } else { beginInsertRows(QModelIndex(), cursz , prvsz - 1); v.swap(fresh); endInsertRows(); } }
C++ (Qt) void container::add_mapping(Key key, Type &value){ std::lock_guard<std::mutex> l(mutex); auto it = unordered_map.find(key); if(it == unordered_map.end()){ Type *data = new Type; unordered_map.insert(std::make_pair(key, data)); vectror.push_back(data); } else{ *(it.operator->()->second) = value; } } std::vector<Type> container::get_vector(){ std::lock_guard<std::mutex> l(mutex); std::vector<Type> v; for(auto e : vector){ v.push_back(*e); } return v;}
C++ (Qt)void TreeView::mousePressEvent(QMouseEvent *e){ if(e->modifiers() & Qt::Controlmodifier) { QModelIndex idx = indexAt(e->pos()); QModelIndex topLeft = model()->index(idx.row(), 0, QModelIndex()); QModelIndex bottomRight = model()->index(idx.row(), model()->columnCount() - 1, QModelIndex()); QItemSelection selection(topLeft, bottomRight); selectionModel()->select(selection, QItemSelectionModel::Select); } return QTreeView::mousePressEvent(e);}