void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { if (topLeft.parent().isValid()) return; if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column()) return; for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { WContainerWidget *w = dynamic_cast<WContainerWidget *>(impl_->widget(i)); WAnchor *anchor = dynamic_cast<WAnchor *>(w->widget(0)); WText *value = dynamic_cast<WText *>(anchor->widget(0)); WModelIndex index = model_->index(i, modelColumn_); boost::any d = index.data(); value->setText(asString(d)); TextFormat format = index.flags() & ItemIsXHTMLText ? XHTMLText : PlainText; value->setTextFormat(format); boost::any d2 = model_->data(i, modelColumn_, UserRole); if (d2.empty()) d2 = d; value->setAttributeValue("sug", asString(d2)); } }
int GitModel::rowCount(const WModelIndex& index) const { // we are looking for the git SHA1 id of a tree object (since only folders // may contain children). Git::ObjectId objectId; int treeId; if (index.isValid()) { // only column 0 items may contain children if (index.column() != 0) return 0; Git::Object o = getObject(index); if (o.type == Git::Tree) { objectId = o.id; treeId = getTreeId(index.internalId(), index.row()); } else // not a folder: no children return 0; } else { treeId = 0; // the index corresponds to the root object if (treeData_.empty()) // model not yet loaded ! return 0; else objectId = treeData_[0].treeObject(); } return treeData_[treeId].rowCount(); }
WModelIndexList WAbstractItemModel::match(const WModelIndex& start, int role, const boost::any& value, int hits, WFlags<MatchFlag> flags) const { WModelIndexList result; const int rc = rowCount(start.parent()); for (int i = 0; i < rc; ++i) { int row = start.row() + i; if (row >= rc) { if (!(flags & MatchWrap)) break; else row -= rc; } WModelIndex idx = index(row, start.column(), start.parent()); boost::any v = data(idx, role); if (Impl::matchValue(v, value, flags)) result.push_back(idx); } return result; }
WModelIndex WIdentityProxyModel::mapFromSource(const WModelIndex &sourceIndex) const { if (!sourceIndex.isValid()) return WModelIndex(); return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer()); }
bool ChannelsModel::setData(const WModelIndex &index, const boost::any &value, int role) { if (index.column() == 3) { QSharedPointer<common::User> du; QSharedPointer<Channel> ch; ch = m_availableChannels->at(index.row()); du = common::DbSession::getInstance().getTokensMap().find(std::string(m_token))->second; bool subscribed=false; for (int i = 0; i < m_subscribedChannels->size(); i++) { if (m_subscribedChannels->at(i) == ch) { subscribed = true; break; } } if (subscribed) { //unsubscribe common::DbSession::getInstance().unsubscribe(du,ch); } else { //subscribe common::DbSession::getInstance().subscribe(du,ch); } // index.data(Wt::CheckStateRole)=; dataChanged().emit(index, index); this->channelsUpdated.emit(); return true; } return false; }
boost::any GitModel::data(const WModelIndex& index, int role) const { if (!index.isValid()) return boost::any(); /* Only 3 data roles on column 0 data are supported: * - DisplayRole: the file name * - DecorationRole: an icon (folder or file) * - ContentsRole: the file contents */ if (index.column() == 0) { Git::Object object = getObject(index); if (role == DisplayRole) { if (object.type == Git::Tree) return object.name + '/'; else return object.name; } else if (role == DecorationRole) { if (object.type == Git::Blob) return static_cast<const char*>("resources/icons/git-blob.png"); else if (object.type == Git::Tree) return static_cast<const char*>("resources/icons/git-tree.png"); } else if (role == ContentsRole) { if (object.type == Git::Blob) return git_.catFile(object.id); } else if (role == FilePathRole) { return boost::any(); } } return boost::any(); }
WFlags<ItemFlag> ChannelsModel::flags(const WModelIndex &index) const { if (index.column() == 3) { return Wt::ItemIsUserCheckable; } return 0; // return WFlags<ItemFlag>(); }
virtual cpp17::any data(const WModelIndex& index, ItemDataRole role = ItemDataRole::Display) const { if (!index.isValid()) return cpp17::any(); Git::Object object = getObject(index); switch (index.column()) { case 0: if (role == ItemDataRole::Display) { if (object.type == Git::Tree) return object.name + '/'; else return object.name; } else if (role == ItemDataRole::Decoration) { if (object.type == Git::Blob) return std::string("icons/git-blob.png"); else if (object.type == Git::Tree) return std::string("icons/git-tree.png"); } else if (role == ContentsRole) { if (object.type == Git::Blob) return git_.catFile(object.id); } break; case 1: if (role == ItemDataRole::Display) { if (object.type == Git::Tree) return std::string("Folder"); else { std::string suffix = getSuffix(object.name); if (suffix == "C" || suffix == "cpp") return std::string("C++ Source"); else if (suffix == "h" || (suffix == "" && !topLevel(index))) return std::string("C++ Header"); else if (suffix == "css") return std::string("CSS Stylesheet"); else if (suffix == "js") return std::string("JavaScript Source"); else if (suffix == "md") return std::string("Markdown"); else if (suffix == "png" || suffix == "gif") return std::string("Image"); else if (suffix == "txt") return std::string("Text"); else return cpp17::any(); } } } return cpp17::any(); }
WModelIndex WSortFilterProxyModel::mapToSource(const WModelIndex& proxyIndex) const { if (proxyIndex.isValid()) { Item *parentItem = parentItemFromIndex(proxyIndex); return sourceModel()->index(parentItem->proxyRowMap_[proxyIndex.row()], proxyIndex.column(), parentItem->sourceIndex_); } else return WModelIndex(); }
WFlags<ItemFlag> ArnModelW::flags(const WModelIndex& index) const { if (!index.isValid()) { return WFlags<ItemFlag>(0); } if (index.column() == 1) { return WAbstractItemModel::flags( index) | Wt::ItemIsEditable; } else { return WAbstractItemModel::flags( index); } }
bool WModelIndex::UnorderedLess::operator() (const WModelIndex& i1, const WModelIndex& i2) const { if (!i1.isValid()) return i2.isValid(); else if (!i2.isValid()) return false; else if (i1 == i2) return false; else if (i1.model() != i2.model()) { LOG_ERROR("comparing indexes from different models are you?"); return false; } else if (i1.row() < i2.row()) return true; else if (i1.row() > i2.row()) return false; else if (i1.column() < i2.column()) return true; else if (i1.column() > i2.column()) return false; else return i1.internalId_ < i2.internalId_; }
void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { if (topLeft.parent().isValid()) return; if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column()) return; for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { WContainerWidget *w = dynamic_cast<WContainerWidget *>(content_->widget(i)); WText *value = dynamic_cast<WText *>(w->widget(0)); boost::any d = model_->data(i, modelColumn_); value->setText(asString(d)); boost::any d2 = model_->data(i, modelColumn_, UserRole); if (d2.empty()) d2 = d; value->setAttributeValue("sug", asString(d2)); } }
void WSortFilterProxyModel::sourceDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { bool refilter = dynamic_ && (filterKeyColumn_ >= topLeft.column() && filterKeyColumn_ <= bottomRight.column()); bool resort = dynamic_ && (sortKeyColumn_ >= topLeft.column() && sortKeyColumn_ <= bottomRight.column()); WModelIndex parent = mapFromSource(topLeft.parent()); Item *item = itemFromIndex(parent); for (int row = topLeft.row(); row <= bottomRight.row(); ++row) { int oldMappedRow = item->sourceRowMap_[row]; bool propagateDataChange = oldMappedRow != -1; if (refilter || resort) { // Determine new insertion point: erase it temporarily for this if (oldMappedRow != -1) item->proxyRowMap_.erase(item->proxyRowMap_.begin() + oldMappedRow); int newMappedRow = mappedInsertionPoint(row, item); if (oldMappedRow != -1) item->proxyRowMap_.insert(item->proxyRowMap_.begin() + oldMappedRow, row); if (newMappedRow != oldMappedRow) { if (oldMappedRow != -1) { beginRemoveRows(parent, oldMappedRow, oldMappedRow); item->proxyRowMap_.erase (item->proxyRowMap_.begin() + oldMappedRow); rebuildSourceRowMap(item); endRemoveRows(); } if (newMappedRow != -1) { beginInsertRows(parent, newMappedRow, newMappedRow); item->proxyRowMap_.insert (item->proxyRowMap_.begin() + newMappedRow, row); rebuildSourceRowMap(item); endInsertRows(); } propagateDataChange = false; } } if (propagateDataChange) { WModelIndex l = sourceModel()->index(row, topLeft.column(), topLeft.parent()); WModelIndex r = sourceModel()->index(row, bottomRight.column(), topLeft.parent()); dataChanged().emit(mapFromSource(l), mapFromSource(r)); } } }
void DataStore::modelDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { if (dataLocation_ == ClientSide) { for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { if (recordIds_[i] == -1) continue; for (unsigned j = 0; j < columns_.size(); ++j) { const Column& c = columns_[j]; if (c.modelColumn >= topLeft.column() && c.modelColumn <= bottomRight.column()) { jsChanges_ += "store.getById(" + boost::lexical_cast<std::string>(recordIds_[i]) + ").set('" + c.fieldName + "'," + dataAsJSLiteral(i, c.modelColumn) + ");"; } } } } else needRefresh_ = true; }
int ArnModelW::rowCount(const WModelIndex& parent) const { // qDebug() << "### arnModelW rowCount: Check"; if (parent.column() > 0) return 0; ArnNode* parentNode = nodeFromIndex( parent); if (!parentNode) { // Should not be ... qDebug() << "### arnModelW rowCount: parent=null Grandparent=" << nodeFromIndex( this->parent( parent))->path(); return 0; } int ret = parentNode->_children.size(); // qDebug() << "### arnModelW rowCount: col0 parent=" << parentNode->path() // << " expand=" << parentNode->_expandState.e << " ret=" << ret; return ret; }
virtual int rowCount(const WModelIndex& parent = WModelIndex()) const { int treeId; if (parent.isValid()) { if (parent.column() != 0) return 0; Git::Object o = getObject(parent); if (o.type == Git::Tree) { // is a folder treeId = getTreeId(parent.internalId(), parent.row()); } else // is a file return 0; } else { treeId = 0; } return treeData_[treeId].rowCount(); }
WModelIndex WSortFilterProxyModel::mapFromSource(const WModelIndex& sourceIndex) const { if (sourceIndex.isValid()) { WModelIndex sourceParent = sourceIndex.parent(); Item *item = itemFromSourceIndex(sourceParent); int row = item->sourceRowMap_[sourceIndex.row()]; if (row != -1) return createIndex(row, sourceIndex.column(), static_cast<void *>(item)); else return WModelIndex(); } else return WModelIndex(); }
boost::any ChannelsModel::data(const WModelIndex & index, int role) const { if (role == Wt::DisplayRole || role == Wt::EditRole || role == ToolTipRole || CheckStateRole) { switch (index.column()) { case 0: return m_availableChannels->at(index.row())->getName(); case 1: return m_availableChannels->at(index.row())->getDescription(); case 2: return m_availableChannels->at(index.row())->getRadius(); case 3: { // WCheckBox *Check; // Check = new WCheckBox(/*dynamic_cast<WContainerWidget*>(WObject::parent())*/); for (int i=0;i<m_subscribedChannels->size();i++) { if (m_subscribedChannels->at(i)==m_availableChannels->at(index.row())) { // Check->setChecked(true); // return boost::any(Check); if (role == Wt::CheckStateRole) return true; return ""; } } // return *Check; if (role == Wt::CheckStateRole) return false; return ""; } default: return "undefined"; } return "indefined"; } else { return boost::any(); } }
void WCartesianChart::modelDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { if (XSeriesColumn_ >= topLeft.column() && XSeriesColumn_ <= bottomRight.column()) { update(); return; } for (unsigned i = 0; i < series_.size(); ++i) { if ((series_[i].modelColumn() >= topLeft.column() && series_[i].modelColumn() <= bottomRight.column()) || (series_[i].XSeriesColumn() >= topLeft.column() && series_[i].XSeriesColumn() <= bottomRight.column())) { update(); break; } } }
WModelIndex WIdentityProxyModel::mapToSource(const WModelIndex &proxyIndex) const { if (!sourceModel() || !proxyIndex.isValid()) return WModelIndex(); return createSourceIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer()); }
FileEditDialog(WAbstractItemModel *model, const WModelIndex& item) : WDialog("Edit..."), model_(model), item_(item) { int modelRow = item_.row(); resize(300, WLength::Auto); /* * Create the form widgets, and load them with data from the model. */ // name nameEdit_ = new WLineEdit(asString(model_->data(modelRow, 1))); // type typeEdit_ = new WComboBox(); typeEdit_->addItem("Document"); typeEdit_->addItem("Spreadsheet"); typeEdit_->addItem("Presentation"); typeEdit_->setCurrentIndex (typeEdit_->findText(asString(model_->data(modelRow, 2)))); // size sizeEdit_ = new WLineEdit(asString(model_->data(modelRow, 3))); sizeEdit_->setValidator (new WIntValidator(0, std::numeric_limits<int>::max(), this)); // created createdPicker_ = new WDatePicker(); createdPicker_->lineEdit()->validator()->setMandatory(true); createdPicker_->setFormat(FileModel::dateEditFormat); createdPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 4))); // modified modifiedPicker_ = new WDatePicker(); modifiedPicker_->lineEdit()->validator()->setMandatory(true); modifiedPicker_->setFormat(FileModel::dateEditFormat); modifiedPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 5))); /* * Use a grid layout for the labels and fields */ WGridLayout *layout = new WGridLayout(); WLabel *l; int row = 0; layout->addWidget(l = new WLabel("Name:"), row, 0); layout->addWidget(nameEdit_, row, 1); l->setBuddy(nameEdit_); ++row; layout->addWidget(l = new WLabel("Type:"), row, 0); layout->addWidget(typeEdit_, row, 1); l->setBuddy(typeEdit_); ++row; layout->addWidget(l = new WLabel("Size:"), row, 0); layout->addWidget(sizeEdit_, row, 1); l->setBuddy(sizeEdit_); ++row; layout->addWidget(l = new WLabel("Created:"), row, 0); layout->addWidget(createdPicker_->lineEdit(), row, 1); layout->addWidget(createdPicker_, row, 2); l->setBuddy(createdPicker_->lineEdit()); ++row; layout->addWidget(l = new WLabel("Modified:"), row, 0); layout->addWidget(modifiedPicker_->lineEdit(), row, 1); layout->addWidget(modifiedPicker_, row, 2); l->setBuddy(modifiedPicker_->lineEdit()); ++row; WPushButton *b; WContainerWidget *buttons = new WContainerWidget(); buttons->addWidget(b = new WPushButton("Save")); b->clicked().connect(this, &WDialog::accept); contents()->enterPressed().connect(this, &WDialog::accept); buttons->addWidget(b = new WPushButton("Cancel")); b->clicked().connect(this, &WDialog::reject); /* * Focus the form widget that corresonds to the selected item. */ switch (item.column()) { case 2: typeEdit_->setFocus(); break; case 3: sizeEdit_->setFocus(); break; case 4: createdPicker_->lineEdit()->setFocus(); break; case 5: modifiedPicker_->lineEdit()->setFocus(); break; default: nameEdit_->setFocus(); break; } layout->addWidget(buttons, row, 0, 0, 3, AlignCenter); layout->setColumnStretch(1, 1); contents()->setLayout(layout); finished().connect(this, &FileEditDialog::handleFinish); show(); }
boost::any ArnModelW::data(const WModelIndex& index, int role) const { // qDebug() << "### arnModelW data:"; ArnNode* node = nodeFromIndex( index); Q_ASSERT( node); switch (role) { case Wt::DisplayRole: // Fall throu case Wt::EditRole: // Fall throu case ItemDataRoleUser::DataExt: // if (!node) return boost::any(); if (!node) { return WString("<Null>"); // Should not be ... } switch (index.column()) { case 0: // qDebug() << "### arnModelW data: Col0 Disp/Edit path=" << node->path(); return toWString( node->name( Arn::NameF::NoFolderMark)); case 1: boost::any retVal = adjustedNodeData( node, role); return retVal; } break; case Wt::ToolTipRole: if (node->isFolder() && node->_infoChild) { QString info = node->_infoChild->toString(); QRegExp rx("<tt>(.*)</tt>"); if (rx.indexIn( info) >= 0) { return toWString( rx.cap(1)); } } break; case ItemDataRoleUser::Help: if (node->isFolder() && node->_helpChild) { QString help = node->_helpChild->toString(); return toWString( help); } break; case ItemDataRoleUser::EnumList: if (index.column() < 1) return boost::any(); if (node->isFolder() && node->_setMap && node->_valueChild) { // qDebug() << "EnumList: " << node->_setMap->values(); return node->_setMap->values(); } break; case ItemDataRoleUser::Path: return node->path(); } return boost::any(); }