QVariant ProfileTableModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    if (role == Qt::DisplayRole) {
        const ProfileTableRow& row = m_rowData[index.row()];

        switch(index.column()) {
        case COLUMN_PROGRAM:
            return row.program;
        case COLUMN_USAGES:
            return QLocale::system().toString(row.uses);
        case COLUMN_GPU_TIME:
            return Profiling::getTimeString(row.gpuTime);
        case COLUMN_CPU_TIME:
            return Profiling::getTimeString(row.cpuTime);
        case COLUMN_PIXELS_DRAWN:
            return QLocale::system().toString((qlonglong)row.pixels);
        case COLUMN_GPU_AVERAGE:
            return Profiling::getTimeString((row.uses <= 0) ? 0 : (row.gpuTime / row.uses));
        case COLUMN_CPU_AVERAGE:
            return Profiling::getTimeString((row.uses <= 0) ? 0 : (row.cpuTime / row.uses));
        case COLUMN_PIXELS_AVERAGE:
            return QLocale::system().toString((row.uses <= 0) ? 0 : (row.pixels / row.uses));
        }
    } else if (role == Qt::TextAlignmentRole) {
        return Qt::AlignRight;
    }

    return QVariant();
}
Example #2
0
void
ProgressTreeDelegate::paintViewStep( QPainter* painter,
                                     const QStyleOptionViewItem& option,
                                     const QModelIndex& index ) const
{
    QRect textRect = option.rect.adjusted( ITEM_MARGIN,
                                           ITEM_MARGIN,
                                           ITEM_MARGIN,
                                           ITEM_MARGIN );
    QFont font = qApp->font();
    font.setPointSize( VS_FONTSIZE );
    font.setBold( false );
    painter->setFont( font );

    bool isCurrent = false;
    isCurrent = index.data( ProgressTreeModel::ProgressTreeItemCurrentRole ).toBool();

    if ( isCurrent )
    {
        painter->setPen( Calamares::Branding::instance()->
                         styleString( Calamares::Branding::SidebarTextSelect ) );
        QString textHighlight = Calamares::Branding::instance()->
                           styleString( Calamares::Branding::SidebarTextHighlight );
        if ( textHighlight.isEmpty() )
            painter->setBrush( APP->mainWindow()->palette().background() );
        else
            painter->setBrush( QColor( textHighlight ) );
    }

    painter->fillRect( option.rect, painter->brush().color() );
    painter->drawText( textRect, index.data().toString() );
}
Example #3
0
int TreeModel::columnCount(const QModelIndex &parent) const
{
    if (parent.isValid())
        return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
    else
        return rootItem->columnCount();
}
Example #4
0
int HistoryMenuModel::rowCount(const QModelIndex &parent) const
{
    if (parent.column() > 0)
        return 0;

    if (!parent.isValid()) {
        int folders = sourceModel()->rowCount();
        int bumpedItems = bumpedRows();
        if (bumpedItems <= MOVEDROWS
            && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0)))
            --folders;
        return bumpedItems + folders;
    }

    if (parent.internalId() == -1) {
        if (parent.row() < bumpedRows())
            return 0;
    }

    QModelIndex idx = mapToSource(parent);
    int defaultCount = sourceModel()->rowCount(idx);
    if (idx == sourceModel()->index(0, 0))
        return defaultCount - bumpedRows();
    return defaultCount;
}
Example #5
0
bool PhraseModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
    int row = index.row();
    int column = index.column();

    if (!index.isValid() || row >= plist.count() || role != Qt::EditRole)
        return false;

    Phrase *phrase = plist.at(row);

    switch (column) {
    case 0:
        phrase->setSource(value.toString());
        break;
    case 1:
        phrase->setTarget(value.toString());
        break;
    case 2:
        phrase->setDefinition(value.toString());
        break;
    default:
        return false;
    }

    emit dataChanged(index, index);
    return true;
}
Example #6
0
ObjectType ObjectTypesModel::objectTypeAt(const QModelIndex &index) const
{
    if (!index.isValid())
        return ObjectType();

    return mObjectTypes.at(index.row());
}
Example #7
0
QVariant HistoryModel::data(const QModelIndex &index, int role) const
{
    QList<HistoryEntry> lst = m_history->history();
    if (index.row() < 0 || index.row() >= lst.size())
        return QVariant();

    const HistoryEntry &item = lst.at(index.row());
    switch (role) {
    case DateTimeRole:
        return item.dateTime;
    case DateRole:
        return item.dateTime.date();
    case UrlRole:
        return QUrl(item.url);
    case UrlStringRole:
        return item.url;
    case TitleRole:
        return item.userTitle();
    case Qt::DisplayRole:
    case Qt::EditRole: {
        switch (index.column()) {
        case 0:
            return item.userTitle();
        case 1:
            return item.url;
        }
    }
    case Qt::DecorationRole:
        if (index.column() == 0) {
            return BrowserApplication::instance()->icon(item.url);
        }
    }
    return QVariant();
}
Example #8
0
void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(widget);
	if (polygon().isEmpty())
		return;

	// This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here,
	// after all we need to plot the correct velocities colors later.
	setPen(Qt::NoPen);
	QGraphicsPolygonItem::paint(painter, option, widget);

	// Here we actually paint the boundaries of the Polygon using the colors that the model provides.
	// Those are the speed colors of the dives.
	QPen pen;
	pen.setCosmetic(true);
	pen.setWidth(2);
	QPolygonF poly = polygon();
	// This paints the colors of the velocities.
	for (int i = 1, count = dataModel->rowCount(); i < count; i++) {
		QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR);
		pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>()));
		painter->setPen(pen);
		painter->drawLine(poly[i - 1], poly[i]);
	}
}
Example #9
0
/**
 * @brief ClientList::data overloaded function for displaying the data in the table.
 * @param index
 * @param role
 * @return
 */
QVariant ClientList::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    int col = index.column();

    if (role == Qt::DisplayRole)
    {
        if (clients.size() > 0) {
            if (col == 0)
                return clients.at(row)->getAddress();
        }
    }
    if (role == Qt::BackgroundRole) {
        if (clients.size() > 0) {
            if (col == 1) {
                if(clients.at(row)->isBroadcasting)
                    return QBrush(Qt::green);
                else
                    return QBrush(Qt::red);
            }
            if (col == 2) {
                if(clients.at(row)->isListening)
                    return QBrush(Qt::green);
                else
                    return QBrush(Qt::red);
            }
        }
    }
    return QVariant();
}
Example #10
0
QVariant SearchModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    SearchResult *item = static_cast<SearchResult *>(index.internalPointer());

    switch (role) {
    case Qt::DisplayRole:
        switch (index.column()) {
        case 0:
            if (item->parentName.isEmpty())
                return item->name;
            else
                return QString("%1 (%2)").arg(item->name, item->parentName);
        case 1:
            return QDir(item->docset->documentPath()).absoluteFilePath(item->path);
        default:
            return QVariant();
        }

    case Qt::DecorationRole: {
        return item->docset->symbolTypeIcon(item->type);
    }

    case ItemDataRole::DocsetIconRole:
        return item->docset->icon();

    default:
        return QVariant();
    }
}
Example #11
0
    QVariant data(const QModelIndex &index, int role) const
    {
        if(index.row() < 0 || index.row() > size())
            return QVariant();

        return items[index.row()]->data(static_cast<FieldType>(role));
    }
QVariant KNMusicLyricsDetailListModel::data(const QModelIndex &index,
                                            int role) const
{
    //Check the validation of the data.
    if(!index.isValid())
    {
        //Give back a null data.
        return m_nullData;
    }
    //Get the lyrics list item.
    KNMusicLyricsDownloader::KNMusicLyricsDetails detail=
            m_lyricsList.at(index.row());
    //Check the role.
    switch(role)
    {
    case Qt::DisplayRole:
        return QVariant(detail.title + "\n" + detail.artist);
    case Qt::SizeHintRole:
        return knDpi->size(12, 34);
    case Qt::UserRole:
        return detail.lyricsData;
    default:
        return m_nullData;
    }
}
QNdefMessage
BookmarkSelectionPageListModel::bookmark(const QModelIndex &index) const
{
    return _bookmarkToMessage(m_bookmarks[index.row()].url,
                              m_bookmarks[index.row()].name,
                              m_bookmarks[index.row()].icon);
}
QVariant BtBookshelfTreeModel::data(const QModelIndex & index, int role) const {
    if (!index.isValid() || index.column() != 0)
        return QVariant();

    const Item * const i = static_cast<Item*>(index.internalPointer());
    Q_ASSERT(i != 0);
    switch (role) {

        case Qt::CheckStateRole:
            if (!m_checkable)
                break;

        case BtBookshelfTreeModel::CheckStateRole:
            return i->checkState();

        case BtBookshelfModel::ModulePointerRole:
            /* This case is just an optimization. */
            if (i->type() == Item::ITEM_MODULE) {
                const ModuleItem & mi = *static_cast<const ModuleItem *>(i);
                return qVariantFromValue(static_cast<void *>(&mi.moduleInfo()));
            }
            return 0;

        case Qt::DisplayRole:
        case Qt::DecorationRole:
        case BtBookshelfModel::ModuleHiddenRole:
        default:
            if (i->type() == Item::ITEM_MODULE)
                return data(static_cast<const ModuleItem *>(i)->moduleInfo(), role);

            return i->data(role);

    }
    return QVariant();
}
void AELoadedResourcesTreeView::resourceSelectionChanged(const QItemSelection& current, const QItemSelection& previous)
{
	const QModelIndex index = selectionModel()->currentIndex();
	QVariant var = index.data(ModelRole);
	if (var.isValid())
	{
		Anima::AnimaModel* model = var.value<Anima::AnimaModel*>();
		_resourcesViewer->setSelectedObject(model);
		return;
	}
	var = index.data(ModelInstanceRole);
	if (var.isValid())
	{
		Anima::AnimaModelInstance* instance = var.value<Anima::AnimaModelInstance*>();
		_resourcesViewer->setSelectedObject(instance);
		return;
	}
	var = index.data(MeshRole);
	if (var.isValid())
	{
		Anima::AnimaMesh* mesh = var.value<Anima::AnimaMesh*>();
		_resourcesViewer->setSelectedObject(mesh);
		return;
	}
	var = index.data(MeshInstanceRole);
	if (var.isValid())
	{
		Anima::AnimaMeshInstance* instance = var.value<Anima::AnimaMeshInstance*>();
		_resourcesViewer->setSelectedObject(instance);
		return;
	}
}
void QuickInspectorWidget::itemModelDataChanged(const QModelIndex &topLeft,
                                                const QModelIndex &bottomRight,
                                                const QVector<int> &roles)
{
    if (!roles.contains(QuickItemModelRole::ItemEvent))
        return;

    for (int i = topLeft.row(); i <= bottomRight.row(); i++) {
        const QModelIndex index = ui->itemTreeView->model()->index(i, 0, topLeft.parent());
        const auto state = index.data(RemoteModelRole::LoadingState).value<RemoteModelNodeState::NodeStates>();
        if (state & RemoteModelNodeState::Empty || ~state & RemoteModelNodeState::Outdated)
            continue;

        QVariantAnimation *colorAnimation = new QVariantAnimation(this);
        QPersistentModelIndex persistentIndex(index);
        connect(colorAnimation, &QVariantAnimation::valueChanged,
                ui->itemTreeView->itemDelegate(), [persistentIndex, this](const QVariant &value) {
            qobject_cast<QuickItemDelegate *>(ui->itemTreeView->itemDelegate())->setTextColor(value,
                                                                                              persistentIndex);
        });
        colorAnimation->setStartValue(QColor(129, 0, 129));
        colorAnimation->setEndValue(QColor(129, 0, 129, 0));
        colorAnimation->setDuration(2000);
        colorAnimation->start(QAbstractAnimation::DeleteWhenStopped);
    }
}
Example #17
0
QModelIndex ApiTraceModel::index(int row, int column,
                                 const QModelIndex &parent) const
{
    if (parent.isValid() && parent.column() != 0)
        return QModelIndex();

    ApiTraceEvent *event = item(parent);
    if (event) {
        if (event->type() != ApiTraceEvent::Frame) {
            qDebug()<<"got a valid parent but it's not a frame "<<event->type();
            return QModelIndex();
        }
        ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
        ApiTraceCall *call = frame->calls.value(row);
        if (call)
            return createIndex(row, column, call);
        else
            return QModelIndex();
    } else {
        ApiTraceFrame *frame = m_trace->frameAt(row);
        if (frame)
            return createIndex(row, column, frame);
        else
            return QModelIndex();
    }
    return QModelIndex();
}
Example #18
0
void View::Invoicing::OperationTable::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
{
    switch(hint) {
    case QAbstractItemDelegate::NoHint:
    case QAbstractItemDelegate::RevertModelCache:
    {
        if(currentIndex().column() == ColumnOperationId && (model() -> data(currentIndex())).toString().isEmpty()) {
            QTableView::closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
            model() -> removeRows(currentIndex().row(), 1);
        } else
            QTableView::closeEditor(editor, hint);
    } break;
    case QAbstractItemDelegate::EditNextItem:
    case QAbstractItemDelegate::EditPreviousItem:
    case QAbstractItemDelegate::SubmitModelCache:
    {
        if(currentIndex().column() == ColumnOperationId && (model() -> data(currentIndex())).toString().isEmpty()) {
            QTableView::closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
            emit productNotFound();
            edit(currentIndex());

        } else {
            QModelIndex index = firstEditableIndex((hint == QAbstractItemDelegate::EditPreviousItem) ? Backward : Forward);
            QTableView::closeEditor(editor, QAbstractItemDelegate::NoHint);
            setCurrentIndex(index);
            if(index.column() != ColumnOperationPrice)
                edit(index);
        }
    } break;
    default:
        QTableView::closeEditor(editor, hint);
    }

}
Example #19
0
bool EvParametersModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    EvParameter * parameter = m_process->child<EvParameter>(index.row());
    if(role == Qt::EditRole){
        switch (index.column()) {
        case 0:{
            m_commandsInterface->setObjectProperty(
                        parameter,
                        "name",
                        value );

            Q_EMIT dataChanged(index,index);
            return true;
        }
        case 2:{
            m_commandsInterface->setObjectProperty(
                        parameter,
                        "textualValue",
                        value );

            Q_EMIT dataChanged(index,index);
            return true;
        }
        default:
            break;
        }
    }
    return false;


}
Example #20
0
QVariant BreakpointModel::data(const QModelIndex& index, int role) const
{
    if (!index.parent().isValid() && index.row() < m_breakpoints.count()) {
        return m_breakpoints.at(index.row())->data(index.column(), role);
    }
    return QVariant();
}
Example #21
0
int HistoryMenuModel::bumpedRows() const
{
    QModelIndex first = m_treeModel->index(0, 0);
    if (!first.isValid())
        return 0;
    return qMin(m_treeModel->rowCount(first), MOVEDROWS);
}
Example #22
0
bool KDevelop::BreakpointModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
    if (!index.parent().isValid() && index.row() < m_breakpoints.count() && (role == Qt::EditRole || role == Qt::CheckStateRole)) {
        return m_breakpoints.at(index.row())->setData(index.column(), value);
    }
    return false;
}
Example #23
0
QModelIndex HistoryMenuModel::mapFromSource(const QModelIndex &sourceIndex) const
{
    // currently not used or autotested
    Q_ASSERT(false);
    int sr = m_treeModel->mapToSource(sourceIndex).row();
    return createIndex(sourceIndex.row(), sourceIndex.column(), sr);
}
Example #24
0
void MethodsTab::methodContextMenu(const QPoint &pos)
{
  const QModelIndex index = m_ui->methodView->indexAt(pos);
  if (!index.isValid() || !m_interface->hasObject()) {
    return;
  }

  const QMetaMethod::MethodType methodType =
    index.data(ObjectMethodModelRole::MetaMethodType).value<QMetaMethod::MethodType>();
  QMenu contextMenu;
  QAction *invokeAction = 0, *connectToAction = 0;
  if (methodType == QMetaMethod::Slot || methodType == QMetaMethod::Method) {
    invokeAction = contextMenu.addAction(tr("Invoke"));
  } else if (methodType == QMetaMethod::Signal) {
    connectToAction = contextMenu.addAction(tr("Connect to"));
    invokeAction = contextMenu.addAction(tr("Emit"));
  } else {
    return; // Can't do any action, so don't try to show an empty context menu.
  }

  QAction *action = contextMenu.exec(m_ui->methodView->viewport()->mapToGlobal(pos));
  if (action == invokeAction) {
    methodActivated(index);
  } else if (action == connectToAction) {
    m_interface->connectToSignal();
  }
}
Example #25
0
QVariant PhraseModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    int column = index.column();

    if (row >= plist.count() || !index.isValid())
        return QVariant();

    Phrase *phrase = plist.at(row);

    if (role == Qt::DisplayRole || (role == Qt::ToolTipRole && column != 2)) {
        switch (column) {
        case 0: // source phrase
            return phrase->source().simplified();
        case 1: // translation
            return phrase->target().simplified();
        case 2: // definition
            return phrase->definition();
        }
    }
    else if (role == Qt::EditRole && column != 2) {
        switch (column) {
        case 0: // source phrase
            return phrase->source();
        case 1: // translation
            return phrase->target();
        }
    }

    return QVariant();
}
Example #26
0
QVariant RSSModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) return QVariant();

    auto *item = static_cast<RSS::Item *>(getAttachedItem(index));
    Q_ASSERT(item);

    if (role == ItemPtrRole)
        return QVariant::fromValue<RSS::Item *>(item);

    if ((index.column() == 0) && (role == Qt::DecorationRole)) {
        if (qobject_cast<RSS::Folder *>(item))
            return GuiIconProvider::instance()->getIcon(QStringLiteral("inode-directory"));

        auto *feed = static_cast<RSS::Feed *>(item);
        if (feed->isLoading())
            return QIcon(QStringLiteral(":/icons/loading.png"));
        if (feed->hasError())
            return GuiIconProvider::instance()->getIcon(QStringLiteral("unavailable"));

        QIcon feedIcon = m_feedIcons.value(item);
        return ((feedIcon.availableSizes().size() == 0)
                ? GuiIconProvider::instance()->getIcon(QStringLiteral("application-rss+xml"))
                : feedIcon);
    }

    if ((index.column() == 0) && (role == Qt::DisplayRole)) {
        if (item->id() == 0)
            return QString(QStringLiteral("%1 (%2)")).arg(tr("Unread")).arg(item->unreadCount());
        return QString(QStringLiteral("%1 (%2/%3)"))
                .arg(item->name()).arg(item->unreadCount()).arg(item->articles().count());
    }

    return QVariant();
}
Example #27
0
bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent)
{
    TreeItem *parentItem;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<TreeItem*>(parent.internalPointer());

    if (position < 0 || position > parentItem->childCount())
        return false;

    QList<QVariant> blankList;
    for (int column = 0; column < columnCount(); ++column)
        blankList << QVariant("");

    beginInsertRows(parent, position, position + rows - 1);

    for (int row = 0; row < rows; ++row) {
        TreeItem *newItem = new TreeItem(blankList, parentItem);
        if (!parentItem->insertChild(position, newItem))
            break;
    }

    endInsertRows();
    return true;
}
Example #28
0
QVariant LazyNutObjectListModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= rowCount())
        return QVariant();

    if (role == Qt::DisplayRole)
    {
        switch(index.column())
        {
           case 0:
               return _objHash->value(_objHash->keys().at(index.row()))->name();
           default:
               return QVariant();
        }
    }
    else if (role == Qt::ForegroundRole)
    {
          QBrush brush;
          brush.setColor(Qt::blue);
          return brush;
    }
    else
        return QVariant();
}
Example #29
0
//-----------------------------------------------------------------------------
// Function: FileTypesDelegate::setEditorData()
//-----------------------------------------------------------------------------
void FileTypesDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
    switch (index.column())
    {
    case FILE_TYPES_COL_NAME:
        {
            QComboBox* combo = qobject_cast<QComboBox*>(editor);
            Q_ASSERT_X(combo, "FileTypesDelegate::setEditorData", "Type conversion failed for QComboBox");

            QString text = index.model()->data(index, Qt::DisplayRole).toString();
            combo->setEditText(text);
            break;
        }
        
    case FILE_TYPES_COL_EXTENSIONS:
        {
            QLineEdit* line = qobject_cast<QLineEdit*>(editor);
            Q_ASSERT_X(line, "FileTypesDelegate::setEditorData", "Type conversion failed for QLineEdit");

            QString text = index.model()->data(index, Qt::DisplayRole).toString();
            line->setText(text);
            break;
        }

    default:
        {
            QStyledItemDelegate::setEditorData(editor, index);
            break;
        }
    }
}
Example #30
0
void
ReplaceWidget::updateFromCurrentDevice( QComboBox* devicesComboBox )
{
    QModelIndex index = m_core->deviceModel()->index( devicesComboBox->currentIndex(), 0 );
    if ( !index.isValid() )
        return;

    Device* device = m_core->deviceModel()->deviceForIndex( index );

    QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
    if ( oldModel )
        disconnect( oldModel, 0, this, 0 );

    PartitionModel* model = m_core->partitionModelForDevice( device );
    m_ui->partitionTreeView->setModel( model );
    m_ui->partitionTreeView->expandAll();

    // Must be done here because we need to have a model set to define
    // individual column resize mode
    QHeaderView* header = m_ui->partitionTreeView->header();
    header->setSectionResizeMode( QHeaderView::ResizeToContents );
    header->setSectionResizeMode( 0, QHeaderView::Stretch );

    //updateButtons();
    // Establish connection here because selection model is destroyed when
    // model changes
    connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged,
             this, &ReplaceWidget::onPartitionViewActivated );

    connect( model, &QAbstractItemModel::modelReset, this, &ReplaceWidget::onPartitionModelReset );
}