本文整理汇总了C++中WModelIndex::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ WModelIndex::isValid方法的具体用法?C++ WModelIndex::isValid怎么用?C++ WModelIndex::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WModelIndex
的用法示例。
在下文中一共展示了WModelIndex::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
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();
}
示例2: modelRowsInserted
void WSuggestionPopup::modelRowsInserted(const WModelIndex& parent,
int start, int end)
{
if (filterLength_ != 0 && !filtering_)
return;
if (modelColumn_ >= model_->columnCount())
return;
if (parent.isValid())
return;
for (int i = start; i <= end; ++i) {
WContainerWidget *line = new WContainerWidget();
content_->insertWidget(i, line);
boost::any d = model_->data(i, modelColumn_);
WText *value = new WText(asString(d), PlainText);
boost::any d2 = model_->data(i, modelColumn_, UserRole);
if (d2.empty())
d2 = d;
line->addWidget(value);
value->setAttributeValue("sug", asString(d2));
}
}
示例3: rowCount
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();
}
示例4: setData
bool ArnModelW::setData(const WModelIndex& index,
const boost::any& value, int role)
{
if (index.isValid() && role == Wt::EditRole) {
ArnNode* node = nodeFromIndex( index);
if (!node) return false;
if (node->isFolder()) {
if (node->_valueChild) {
if (node->_setMap) {
node->_valueChild->setValue( node->_setMap->key( toQString( boost::any_cast<WString>(value))));
}
else {
node->_valueChild->setValue( toQString( boost::any_cast<WString>(value)));
}
emitDataChangedI( index);
}
}
else {
if (value.type() == typeid(QVariant))
node->setValue( boost::any_cast<QVariant>(value));
else
node->setValue( toQString( boost::any_cast<WString>(value)));
emitDataChangedI( index);
}
return true;
}
return false;
}
示例5: mapFromSource
WModelIndex WIdentityProxyModel::mapFromSource(const WModelIndex &sourceIndex) const
{
if (!sourceIndex.isValid())
return WModelIndex();
return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
}
示例6: if
bool WModelIndex::operator< (const WModelIndex& i2) const
{
const WModelIndex& i1 = *this;
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;
}
int i1Depth = i1.depth();
int i2Depth = i2.depth();
unsigned e = std::min(i1Depth, i2Depth);
WModelIndex a1 = i1.ancestor(i1Depth - e);
WModelIndex a2 = i2.ancestor(i2Depth - e);
if (a1 == a2)
return i1Depth < i2Depth;
for (unsigned i = e; i > 0; --i) {
WModelIndex p1 = a1.parent();
WModelIndex p2 = a2.parent();
if (p1 == p2) {
if (a1.row() < a2.row())
return true;
else if (a1.row() > a2.row())
return false;
else if (a1.column() < a2.column())
return true;
else
return false;
}
a1 = p1;
a2 = p2;
}
return false; // unreachable code
}
示例7: parent
virtual WModelIndex parent(const WModelIndex& index) const {
if (!index.isValid() || index.internalId() == 0) {
return WModelIndex(); // treeData_[0] is the tree root
} else {
const Tree& item = treeData_[index.internalId()];
return createIndex(item.index(), 0, item.parentId());
}
}
示例8: parent
WModelIndex WSortFilterProxyModel::parent(const WModelIndex& index) const
{
if (index.isValid()) {
Item *parentItem = parentItemFromIndex(index);
return mapFromSource(parentItem->sourceIndex_);
} else
return WModelIndex();
}
示例9: parent
WModelIndex WStandardItemModel::parent(const WModelIndex& index) const
{
if (!index.isValid())
return index;
WStandardItem *parent = static_cast<WStandardItem *>(index.internalPointer());
return indexFromItem(parent);
}
示例10: setData
bool WAbstractItemModel::setData(int row, int column, const boost::any& value,
int role, const WModelIndex& parent)
{
WModelIndex i = index(row, column, parent);
if (i.isValid())
return setData(i, value, role);
else
return false;
}
示例11: parent
WModelIndex ArnModelW::parent(const WModelIndex& index) const
{
// qDebug() << "### arnModelW parent: Check";
if (!index.isValid())
return index;
ArnNode* parentNode = static_cast<ArnNode*>( index.internalPointer());
return indexFromNode( parentNode, 0);
}
示例12: mapFromSource
void WSortFilterProxyModel::sourceRowsAboutToBeRemoved
(const WModelIndex& parent, int start, int end)
{
WModelIndex pparent = mapFromSource(parent);
// distinguish between invalid parent being root item or being filtered out
if (parent.isValid() && !pparent.isValid())
return;
Item *item = itemFromIndex(pparent);
for (int row = start; row <= end; ++row) {
int mappedRow = item->sourceRowMap_[row];
if (mappedRow != -1) {
beginRemoveRows(pparent, mappedRow, mappedRow);
item->proxyRowMap_.erase(item->proxyRowMap_.begin() + mappedRow);
rebuildSourceRowMap(item); // erase may have shifted some
endRemoveRows();
}
}
}
示例13: mapToSource
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();
}
示例14: string
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();
}
示例15: flags
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);
}
}