QVariant BtTreeModel::data(const QModelIndex &index, int role) const { int maxColumns; switch(treeMask) { case RECIPEMASK: maxColumns = BtTreeItem::RECIPENUMCOLS; break; case EQUIPMASK: maxColumns = BtTreeItem::EQUIPMENTNUMCOLS; break; case FERMENTMASK: maxColumns = BtTreeItem::FERMENTABLENUMCOLS; break; case HOPMASK: maxColumns = BtTreeItem::HOPNUMCOLS; break; case MISCMASK: maxColumns = BtTreeItem::MISCNUMCOLS; break; case YEASTMASK: maxColumns = BtTreeItem::YEASTNUMCOLS; break; case STYLEMASK: maxColumns = BtTreeItem::STYLENUMCOLS; break; case FOLDERMASK: maxColumns = BtTreeItem::FOLDERNUMCOLS; break; default: // Backwards compatibility. This MUST be fixed prior to releasing the code maxColumns = BtTreeItem::RECIPENUMCOLS; } if ( !rootItem || !index.isValid() || index.column() < 0 || index.column() >= maxColumns) return QVariant(); if ( role == Qt::ToolTipRole ) return toolTipData(index); if ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::DecorationRole) return QVariant(); BtTreeItem* itm = item(index); if ( role == Qt::DecorationRole && index.column() == 0) { if ( itm->type() == BtTreeItem::FOLDER ) return QIcon(":images/folder.png"); else return QVariant(); } return itm->data(index.column()); }
//------------------------------------------------------------------------------ QVariant ImportedTransactionsModel::data(const QModelIndex& index, int role) const { if ( ! index.isValid()) return QVariant(); if (role == Qt::CheckStateRole) return checkStateData(index); if (role == Qt::DisplayRole) return displayData(index); if (role == Qt::EditRole) return editData(index); if (role == Qt::ToolTipRole) return toolTipData(index); return QVariant(); }
QAction *BtMenuView::newAction(QMenu *parentMenu, const QModelIndex &itemIndex) { QVariant displayData(m_model->data(itemIndex, Qt::DisplayRole)); QVariant iconData(m_model->data(itemIndex, Qt::DecorationRole)); QVariant toolTipData(m_model->data(itemIndex, Qt::ToolTipRole)); QVariant statusTipData(m_model->data(itemIndex, Qt::StatusTipRole)); QVariant whatsThisData(m_model->data(itemIndex, Qt::WhatsThisRole)); QAction *childAction = new QAction(parentMenu); // Set text: if (displayData.canConvert(QVariant::String)) { childAction->setText(displayData.toString()); } // Set icon: if (iconData.canConvert(QVariant::Icon)) { childAction->setIcon(iconData.value<QIcon>()); } // Set tooltip: if (toolTipData.canConvert(QVariant::String)) { childAction->setToolTip(toolTipData.toString()); } // Set status tip: if (statusTipData.canConvert(QVariant::String)) { childAction->setStatusTip(statusTipData.toString()); } // Set whatsthis: if (whatsThisData.canConvert(QVariant::String)) { childAction->setWhatsThis(whatsThisData.toString()); } // Set checkable: if (m_model->flags(itemIndex).testFlag(Qt::ItemIsUserCheckable)) { childAction->setCheckable(true); } // Set checked: QVariant checkData(m_model->data(itemIndex, Qt::CheckStateRole)); bool ok; Qt::CheckState state = (Qt::CheckState) checkData.toInt(&ok); if (ok) { childAction->setChecked(state == Qt::Checked); } return childAction; }
QMenu *BtMenuView::newMenu(QMenu *parentMenu, const QModelIndex &itemIndex) { QVariant displayData(m_model->data(itemIndex, Qt::DisplayRole)); QVariant iconData(m_model->data(itemIndex, Qt::DecorationRole)); QVariant toolTipData(m_model->data(itemIndex, Qt::ToolTipRole)); QVariant statusTipData(m_model->data(itemIndex, Qt::StatusTipRole)); QVariant whatsThisData(m_model->data(itemIndex, Qt::WhatsThisRole)); QMenu *childMenu = new QMenu(parentMenu); // Set text: if (displayData.canConvert(QVariant::String)) { childMenu->setTitle(displayData.toString()); } // Set icon: if (iconData.canConvert(QVariant::Icon)) { childMenu->setIcon(iconData.value<QIcon>()); } // Set tooltip: if (toolTipData.canConvert(QVariant::String)) { childMenu->setToolTip(toolTipData.toString()); } // Set status tip: if (statusTipData.canConvert(QVariant::String)) { childMenu->setStatusTip(statusTipData.toString()); } // Set whatsthis: if (whatsThisData.canConvert(QVariant::String)) { childMenu->setWhatsThis(whatsThisData.toString()); } return childMenu; }