コード例 #1
0
void RealTimeMultiSampleArrayDelegate::createCurrentPositionMarkerPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path) const
{
    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    float currentSampleIndex = option.rect.x()+t_pModel->getCurrentSampleIndex();
    float fDx = ((float)option.rect.width()) / t_pModel->getMaxSamples();
    currentSampleIndex = currentSampleIndex*fDx;

    float yStart = option.rect.topLeft().y();
    float yEnd = option.rect.bottomRight().y();

    path.moveTo(currentSampleIndex,yStart);
    path.lineTo(currentSampleIndex,yEnd);
}
コード例 #2
0
/*!
    \reimp
 */
bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
{
    Q_ASSERT(parent.isValid() ? parent.model() == this : true);
    Q_D(QIdentityProxyModel);
    return d->model->insertColumns(column, count, mapToSource(parent));
}
コード例 #3
0
/*!
    \reimp
 */
int QIdentityProxyModel::rowCount(const QModelIndex& parent) const
{
    Q_ASSERT(parent.isValid() ? parent.model() == this : true);
    Q_D(const QIdentityProxyModel);
    return d->model->rowCount(mapToSource(parent));
}
コード例 #4
0
ファイル: ctkDICOMDatasetView.cpp プロジェクト: jhnstrk/CTK
// -------------------------------------------------------------------------
void ctkDICOMDatasetView::onModelSelected(const QModelIndex &index){
    Q_D(ctkDICOMDatasetView);

    ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(index.model()));

    if(model){
        QModelIndex index0 = index.sibling(index.row(), 0);

        if ( model->data(index0,ctkDICOMModel::TypeRole) == static_cast<int>(ctkDICOMModel::PatientType) ){
            d->onPatientModelSelected(index0);
        }else if ( model->data(index0,ctkDICOMModel::TypeRole) == static_cast<int>(ctkDICOMModel::StudyType) ){
            d->onStudyModelSelected(index0);
        }else if ( model->data(index0,ctkDICOMModel::TypeRole) == static_cast<int>(ctkDICOMModel::SeriesType) ){
            d->onSeriesModelSelected(index0);
        }else if ( model->data(index0,ctkDICOMModel::TypeRole) == static_cast<int>(ctkDICOMModel::ImageType) ){
            d->onImageModelSelected(index0);
        }
    }
}
コード例 #5
0
void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex &index) const
{
    QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
    if (!lineEdit->isModified())
        return;

    QString text = lineEdit->text();
    const QValidator *validator = lineEdit->validator();
    if (validator) {
        int pos;
        if (validator->validate(text, pos) != QValidator::Acceptable)
            return;
    }

    QVariant originalValue = index.model()->data(index, Qt::UserRole);
    QVariant value;

    switch (originalValue.type()) {
    case QVariant::Char:
        value = text.at(0);
        break;
    case QVariant::Color:
        colorExp.exactMatch(text);
        value = QColor(qMin(colorExp.cap(1).toInt(), 255),
                       qMin(colorExp.cap(2).toInt(), 255),
                       qMin(colorExp.cap(3).toInt(), 255),
                       qMin(colorExp.cap(4).toInt(), 255));
        break;
    case QVariant::Date:
        {
            QDate date = QDate::fromString(text, Qt::ISODate);
            if (!date.isValid())
                return;
            value = date;
        }
        break;
    case QVariant::DateTime:
        {
            QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate);
            if (!dateTime.isValid())
                return;
            value = dateTime;
        }
        break;
    case QVariant::Point:
        pointExp.exactMatch(text);
        value = QPoint(pointExp.cap(1).toInt(), pointExp.cap(2).toInt());
        break;
    case QVariant::Rect:
        rectExp.exactMatch(text);
        value = QRect(rectExp.cap(1).toInt(), rectExp.cap(2).toInt(),
                      rectExp.cap(3).toInt(), rectExp.cap(4).toInt());
        break;
    case QVariant::Size:
        sizeExp.exactMatch(text);
        value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt());
        break;
    case QVariant::StringList:
        value = text.split(',');
        break;
    case QVariant::Time:
        {
            QTime time = QTime::fromString(text, Qt::ISODate);
            if (!time.isValid())
                return;
            value = time;
        }
        break;
    default:
        value = text;
        value.convert(originalValue.type());
    }

    model->setData(index, displayText(value), Qt::DisplayRole);
    model->setData(index, value, Qt::UserRole);
}
コード例 #6
0
void TupTimeLineTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_ASSERT(index.isValid());

    QItemDelegate::paint(painter, option, index);
    TupTimeLineTable *table = qobject_cast<TupTimeLineTable *>(index.model()->parent());
    TupTimeLineTableItem *item = dynamic_cast<TupTimeLineTableItem *>(table->itemFromIndex(index));
    
    // draw the background color
    QVariant value = index.data(Qt::BackgroundColorRole);
    
    if (value.isValid()) {
        painter->save();
        
        bool sound = table->isSoundLayer(index.row());
        if (!sound)
            painter->fillRect(option.rect, value.value<QColor>());
        
        painter->restore();
    } else {
        painter->save();
        
        bool sound = table->isSoundLayer(index.row());
        if (!sound) {
            int counter = index.column() + 1;
            if (counter == 1 || counter % 5 == 0) 
                painter->fillRect(option.rect, QColor(230, 230, 230));
            else 
                painter->fillRect(option.rect, Qt::white);
        } 
        
        painter->restore();
    }
    
    // Selection!
    if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
        painter->save();

        QColor color(0, 136, 0, 180);
        if (k->themeName.compare("Dark") == 0)
            color = QColor(80, 80, 80, 180);

        painter->fillRect(option.rect, color);
        painter->restore();
    }
    
    // Draw attributes
    int offset = option.rect.width() - 5;

    if (item && index.isValid()) {
        if (item->isUsed()) {
            painter->save();
            painter->setBrush(Qt::black);
            painter->setRenderHint(QPainter::Antialiasing, true);
            
            if (!item->isSound()) {
                if (item->isLocked()) {
                    painter->setPen(QPen(Qt::red, 1, Qt::SolidLine));
                    painter->setBrush(Qt::red);
                } 
                painter->drawEllipse(option.rect.x() + ((option.rect.width() - offset)/2), 
                                     option.rect.y() + ((option.rect.height() + offset)/2), 
                                     offset, offset);
            } else {
                painter->setBrush(QColor(0, 136, 0));
                painter->drawRect(option.rect.x() + ((option.rect.width() - offset)/2), 
                                  option.rect.y() + ((option.rect.height() + offset)/2), 
                                  offset, offset);
            }
            
            painter->restore();
        }
    }
}
コード例 #7
0
ファイル: ctkDICOMDatasetView.cpp プロジェクト: jhnstrk/CTK
// -------------------------------------------------------------------------
void ctkDICOMDatasetViewPrivate::onSeriesModelSelected(const QModelIndex &index){
    Q_Q(ctkDICOMDatasetView);

    ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(index.model()));

    if(model){
        QModelIndex seriesIndex = index;
        model->fetchMore(seriesIndex);
        int imageCount = model->rowCount(seriesIndex);
        QModelIndex imageIndex = seriesIndex.child(imageCount/2,0);

        this->setImage(imageIndex);
    }else{
        q->clearImages();
    }
}
コード例 #8
0
void AttributeDelegate::EditorSetData(QSpinBox *spinBox, const QModelIndex &index) const
{
    int value = index.model()->data(index, Qt::EditRole).toInt();
    spinBox->setValue(value);
}
コード例 #9
0
void AttributeDelegate::EditorSetData(AttributeEditor *vecEdit, const QModelIndex &index) const
{
    QString value = index.model()->data(index, Qt::EditRole).toString();
    vecEdit->setText(value);
}
コード例 #10
0
void ListViewSingleButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
     //
    // This method paints a new row into the listview
    //

    painter->save();

    // Set normal background color
    painter->setBrush((QColor("#ffffff")));

    // Alternating rows
    if (index.row() % 2) {
        // Set brush to aliceblue
        painter->setBrush((QColor("#f5f5f5")));
    }

    if(index.model()->data(index, Qt::UserRole + 4).toInt() == ConnectionState::Error)
    {
        painter->setBrush(QColor("#FFCCCC"));
    }

    QString textBottom (index.model()->data(index, Qt::UserRole + 101).toString());
    QString textName (index.data(Qt::DisplayRole).toString());

    // Hindergrund zeichnen
    painter->setPen(Qt::NoPen);

    if (textBottom == "__divider__") {
        painter->setBrush(QBrush(QColor("#f2f2f2"))); //0053a1
        painter->drawRect(option.rect);
        painter->setPen(Qt::lightGray);
        painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        if (index.row() == 0) {
            painter->drawLine(option.rect.topLeft(), option.rect.topRight());
        }

        painter->setPen(Qt::black);
        QStyleOptionViewItem nOptionD (option);
        QFont sdasda("Verdana", 10, QFont::Normal);
        //sdasda.setPixelSize(11);
        painter->setFont(sdasda);
        nOptionD.rect.adjust(3, 0, 0, 0);
        painter->drawText(nOptionD.rect, textName);
        rectForRow.insert(index.row(), QRect());
        rectForRow[index.row()] = option.rect;
         painter->restore();
        return;
    }

    painter->drawRect(option.rect);

    // Get text

    QString ip (index.data(Qt::UserRole + 1).toString());
    quint32 lastUsed(index.data(Qt::UserRole + 2).toUInt());
    quint32 lastConnected(index.data(Qt::UserRole + 3).toUInt());
    // Set and calc items width
    int buttonWidth (36* windowsDpiScale());
    int buttonHeight (36* windowsDpiScale());
    int marginRight (10* windowsDpiScale());
    int marginTop (5* windowsDpiScale());

    // Draw delete button
    QStyleOptionViewItem buttonOption (option);
    // -10 is the right margin, the margin is necessary to reset the state when mouse is leaving to the right side
    buttonOption.rect.setRight(buttonWidth + 2 * marginRight);
    buttonOption.rect.setHeight(buttonHeight);
    buttonOption.rect.adjust(10* windowsDpiScale(), option.rect.height() / 2 - buttonHeight / 2, -(marginRight), marginTop + 1);
    buttonOption.rect.setHeight(buttonHeight);
    // Draw delete button and return limits
    // This is to figure out which button is under the mouse position
    rectForRow.insert(index.row(), QRect());
    rectForRow[index.row()] = buttonOption.rect;

    auto drawButton = [](const QModelIndex &index, QPainter *painter, const QRect &rect, int role, ConnectionState conState)
    {
        // Draw delete button
        QStyleOptionButton buttonStyle;

        //
        // Set the button state to enabled
        buttonStyle.state |= QStyle::State_Enabled;
        // Set postion and size to the item
        buttonStyle.rect = rect;
        // Button is a flat button
        buttonStyle.features = QStyleOptionButton::Flat;
        // No text, only an icon
        // Icon default is 16x16
        buttonStyle.iconSize = QSize(16* windowsDpiScale(), 16* windowsDpiScale());
        //

        // Set the button states
        ButtonState state = (ButtonState) index.data(role).toInt();
        QPen pen;
        pen.setWidth(1);

        switch(conState)
        {
        case ConnectionState::Disconnected:
            {
                if(state == Hover) {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#F0D151"));
                } else if(state == Pressed) {

                } else {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#EEEEEC"));
                }
            }
            break;
        case ConnectionState::Connecting:
            {
                if(state == Hover) {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#EEEEEC"));
                } else if(state == Pressed) {
                } else {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#F1C40F"));
                }

            }
            break;
        case ConnectionState::Connected:
            {
                if(state == Hover) {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#EEEEEC"));
                } else if(state == Pressed) {
                } else {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#72C02C"));
                }
            }
            break;
        case ConnectionState::Error:
            {
                if(state == Hover) {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#F0D151"));
                } else if(state == Pressed) {
                } else {
                    pen.setColor("#808080");
                    painter->setBrush(QBrush("#FF0000"));
                }
            }
            break;
        default:
            {
                pen.setColor("#808080");
                painter->setBrush(QBrush("#EEEEEC"));
            }
        }

    // Set the pen and draw the border of the button
    painter->setPen(pen);
    painter->drawRect(buttonStyle.rect);
    painter->setBrush(Qt::NoBrush);

    QRect buttonOption(rect);



    // Draw button
    QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonStyle, painter);
    };

    ConnectionState conState = (ConnectionState)index.data(Qt::UserRole + 4).toInt();

    drawButton(index, painter, buttonOption.rect, Qt::UserRole + 100, conState);

   // this->buttonLimits = this->drawButton(index, painter, buttonOption.rect, this->iconForType(this->buttonIconType, option), Qt::UserRole + 100);


    // Draw text
    QStyleOptionViewItem textOption (option);
    textOption.rect.adjust(buttonWidth + marginRight + 10 + 4, 4, buttonWidth + 2 * marginRight, 0);
    QPen pen;
    pen.setColor(QColor("#2c2c2c"));
    painter->setPen(pen);

    QFont font1("Verdana", 9, QFont::Normal);
    //font1.setPixelSize(11);
    
    QFont font2("Verdana", 7, QFont::Normal);
    //font2.setPixelSize(9);

    painter->setFont(font1);
    painter->drawText(textOption.rect, textName);
    textOption.rect.adjust(0, 13* windowsDpiScale(), 0, 0);
    painter->setFont(font2);
    //painter->drawText(textOption.rect, "Connected: ");
    //textOption.rect.adjust(0, 9, 0, 0);
    //painter->drawText(textOption.rect, "Last used: ");
    //textOption.rect.adjust(0, 9, 0, 0);

    typedef std::chrono::duration<int, std::ratio_multiply<std::chrono::hours::period, std::ratio<24>>::type> days;
    std::chrono::seconds sec((QDateTime::currentDateTime().toTime_t() - lastConnected));

    auto d = std::chrono::duration_cast<days>(sec);
    auto h = std::chrono::duration_cast<std::chrono::hours>(sec - d);
    auto m = std::chrono::duration_cast<std::chrono::minutes>((sec - d - h));
    auto s = std::chrono::duration_cast<std::chrono::seconds>((sec - d - h - m));


    QString day("%1%2 D ");
    day = day.arg(d.count() < 10 ? "0" : "")
        .arg(d.count());

    QString hour("%1%2 H ");
    hour = hour.arg(h.count() < 10 ? "0" : "")
        .arg(h.count());

    QString minute("%1%2 M ");
    minute = minute.arg(m.count() < 10 ? "0" : "")
        .arg(m.count());

    switch(conState)
    {
    case ConnectionState::Connected:
        painter->drawText(textOption.rect, QObject::tr("Connected: ") + (day) + (hour) + (d.count() > 0 ? "" : minute));
        break;
    case ConnectionState::Disconnected:
        painter->drawText(textOption.rect, QObject::tr("Last used: ") + (lastUsed == 0 ? QObject::tr("Never") : QDateTime::fromTime_t(lastUsed).toString("dd.MM.yy hh:mm")));
        break;
    default:
        painter->drawText(textOption.rect, QObject::tr("Last used: ") + (lastUsed == 0 ? QObject::tr("Never") : QDateTime::fromTime_t(lastUsed).toString("dd.MM.yy hh:mm")));
        break;
    };

    if(buttonOption.rect.size() != _lastImgSize)
    {     
        imgStart = imgStart_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgOffline = imgOffline_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgError = imgError_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgOnline = imgOnline_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgStop = imgStop_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgConnecting = imgConnecting_.scaled(buttonOption.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        auto s = buttonOption.rect.size();

        // I dont know why this thing has to be adjusted, but well, it works.
        s.setWidth(s.width() - 1);
        s.setHeight(s.height() - 1);
        movieKeks->setScaledSize(s);

        QSize size(16, 16);

        

        imgIconUsers = imgIconUsers_.scaled(size * windowsDpiScale(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        imgIconAutostart = imgIconAutostart_.scaled(size * windowsDpiScale(), Qt::KeepAspectRatio, Qt::SmoothTransformation);

        _lastImgSize = buttonOption.rect.size();
    }   
    buttonOption.rect.adjust(((buttonWidth) - imgStart.width()) / 2 +1, ((buttonWidth) - imgStart.height()) / 2 + 1, 0, 0);

    ButtonState state = (ButtonState) index.data(Qt::UserRole + 100).toInt();

    switch(conState)
    {
    case ConnectionState::Disconnected:
        {
            if(state == Hover)
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgStart);
            else
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgOffline);
        }
        break;
    case ConnectionState::Connecting:
        {
            if(state == Hover)
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgStop);
            else
            {
                auto pixx = movieKeks->currentPixmap();
                //auto size = imgStart.size();
                ////size.setHeight(size.height() -10);
                //pixx = pixx.scaled(imgStart.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), pixx.toImage());
            }
        }
        break;
    case ConnectionState::Connected:
        {
            if(state == Hover)
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgStop);
            else
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgOnline);
        }
        break;
    case ConnectionState::Error:
        {
            if(state == Hover)
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgStart);
            else
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgError);
        }
        break;
    default:
        {
            if(state == Hover)
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgStart);
            else
                painter->drawImage(buttonOption.rect.left(),  buttonOption.rect.top(), imgOffline);
        }
    }


    static const int iconPadding = 5;

    textOption.rect.setTop(buttonOption.rect.bottom());
    textOption.rect.adjust(0, -imgIconAutostart.height()+2, 0, 0);
    textOption.rect.setWidth(imgIconAutostart.width());

    if(index.data(Qt::UserRole + 5).toBool())
    {
        painter->drawImage(textOption.rect.left(),  textOption.rect.top(), imgIconAutostart);
        textOption.rect.adjust(imgIconAutostart.width() + iconPadding, 0, 0, 0);
    }

    if(index.data(Qt::UserRole + 6).toBool())
    {
        painter->drawImage(textOption.rect.left(),  textOption.rect.top(), imgIconUsers);
        textOption.rect.adjust(imgIconAutostart.width() + iconPadding, 0, 0, 0);
    }
    painter->setPen(Qt::lightGray);
    painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());

    // Restore saved painter
    painter->restore();
}
コード例 #11
0
void AttributeDelegate::EditorSetData(QCheckBox *checkBox, const QModelIndex &index) const
{
    bool value = index.model()->data(index, Qt::EditRole).toBool();
    checkBox->setChecked(value);
}
コード例 #12
0
void RealTimeMultiSampleArrayDelegate::createTriggerThresholdPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, RowVectorPair &data, QPointF &textPosition) const
{
    Q_UNUSED(data)

    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = t_pModel->getKind(index.row());
    double fMaxValue = 1e-9f;

    switch(kind) {
        case FIFFV_STIM_CH: {
            fMaxValue = 5.0;
            if(t_pModel->getScaling().contains(FIFFV_STIM_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_STIM_CH];
            break;
        }
    }

    double fScaleY = option.rect.height()/(2*fMaxValue);
    double triggerThreshold = -1*(t_pModel->getTriggerThreshold());

    path.moveTo(option.rect.topLeft().x(), option.rect.topLeft().y()+option.rect.height()/2+fScaleY*triggerThreshold);
    path.lineTo(option.rect.topRight().x(), option.rect.topLeft().y()+option.rect.height()/2+fScaleY*triggerThreshold);

    textPosition = QPointF(option.rect.topLeft().x()+5, option.rect.topLeft().y()+option.rect.height()/2+fScaleY*triggerThreshold-5);
}
コード例 #13
0
void RealTimeMultiSampleArrayDelegate::createTriggerPath(QPainter *painter, const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, RowVectorPair &data) const
{
    Q_UNUSED(data)

    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    QList<QPair<int,double> > detectedTriggers = t_pModel->getDetectedTriggers();
    QList<QPair<int,double> > detectedTriggersOld = t_pModel->getDetectedTriggersOld();
    QMap<double, QColor> mapTriggerTypeColors = t_pModel->getTriggerColor();

    float yStart = option.rect.topLeft().y();
    float yEnd = option.rect.bottomRight().y();
    float fDx = ((float)option.rect.width()) / t_pModel->getMaxSamples();

    int currentSampleIndex = t_pModel->getCurrentSampleIndex();


    //Newly detected triggers
    for(int u = 0; u < detectedTriggers.size(); ++u) {
        QPainterPath path;

        int triggerPos = detectedTriggers[u].first;

        painter->save();
        if(mapTriggerTypeColors.contains(detectedTriggers[u].second)) {
            painter->setPen(QPen(mapTriggerTypeColors[detectedTriggers[u].second], 1.5, Qt::SolidLine));
        }

        if(triggerPos <= currentSampleIndex + t_pModel->getCurrentOverlapAddDelay()) {
            path.moveTo(triggerPos*fDx,yStart);
            path.lineTo(triggerPos*fDx,yEnd);
        }

        painter->drawPath(path);
        painter->restore();
    }

    //Old detected triggers
    for(int u = 0; u < detectedTriggersOld.size(); ++u) {
        QPainterPath path;

        int triggerPos = detectedTriggersOld[u].first;

        if(triggerPos >= currentSampleIndex + t_pModel->getCurrentOverlapAddDelay()) {
            painter->save();

            if(mapTriggerTypeColors.contains(detectedTriggersOld[u].second)) {
                painter->setPen(QPen(mapTriggerTypeColors[detectedTriggersOld[u].second], 1.5, Qt::SolidLine));
            }

            path.moveTo(triggerPos*fDx,yStart);
            path.lineTo(triggerPos*fDx,yEnd);

            painter->drawPath(path);
            painter->restore();
        }
    }
}
コード例 #14
0
void RealTimeMultiSampleArrayDelegate::createTimeSpacersPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, RowVectorPair &data) const
{
    Q_UNUSED(data)

    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    if(t_pModel->getNumberOfTimeSpacers() > 0)
    {
        //vertical lines
        float distanceSec = float (option.rect.width())/(t_pModel->numVLines()+1);
        float distanceSpacers = distanceSec/(t_pModel->getNumberOfTimeSpacers()+1);

        float yStart = option.rect.topLeft().y();

        float yEnd = option.rect.bottomRight().y();

        for(qint8 t = 0; t < t_pModel->numVLines()+1; ++t) {
            for(qint8 i = 0; i < t_pModel->getNumberOfTimeSpacers(); ++i) {
                float x = (distanceSec*t)+(distanceSpacers*(i+1));
                path.moveTo(x,yStart);
                path.lineTo(x,yEnd);
            }
        }
    }
}
コード例 #15
0
void QScriptDebuggerLocalsWidgetPrivate::_q_expandIndex(const QModelIndex &index)
{
    if (view->model() == index.model())
        view->expand(proxy->mapFromSource(index));
}
コード例 #16
0
ファイル: PartitionPage.cpp プロジェクト: calamares/calamares
void
PartitionPage::updateButtons()
{
    bool create = false, createTable = false, edit = false, del = false, currentDeviceIsVG = false, isDeactivable = false;
    bool isRemovable = false, isVGdeactivated = false;

    QModelIndex index = m_ui->partitionTreeView->currentIndex();
    if ( index.isValid() )
    {
        const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
        Q_ASSERT( model );
        Partition* partition = model->partitionForIndex( index );
        Q_ASSERT( partition );
        bool isFree = KPMHelpers::isPartitionFreeSpace( partition );
        bool isExtended = partition->roles().has( PartitionRole::Extended );

        bool isInVG = m_core->isInVG( partition );

        create = isFree;

        // Keep it simple for now: do not support editing extended partitions as
        // it does not work with our current edit implementation which is
        // actually remove + add. This would not work with extended partitions
        // because they need to be created *before* creating logical partitions
        // inside them, so an edit must be applied without altering the job
        // order.
        // TODO: See if LVM PVs can be edited in Calamares
        edit = !isFree && !isExtended;
        del = !isFree && !isInVG;
    }

    if ( m_ui->deviceComboBox->currentIndex() >= 0 )
    {
        Device* device = nullptr;
        QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
        if ( deviceIndex.isValid() )
            device = m_core->deviceModel()->deviceForIndex( deviceIndex );
        if ( !device )
            cWarning() << "Device for updateButtons is nullptr";
        else if ( device->type() != Device::Type::LVM_Device )
        {
            createTable = true;

#ifdef WITH_KPMCORE4API
            if ( device->type() == Device::Type::SoftwareRAID_Device &&
                 static_cast< SoftwareRAID* >(device)->status() == SoftwareRAID::Status::Inactive )
            {
                createTable = false;
                create = false;
            }
#endif
        }
        else
        {
            currentDeviceIsVG = true;

            LvmDevice* lvmDevice = dynamic_cast<LvmDevice*>(m_core->deviceModel()->deviceForIndex( deviceIndex ));

            isDeactivable = DeactivateVolumeGroupOperation::isDeactivatable( lvmDevice );
            isRemovable = RemoveVolumeGroupOperation::isRemovable( lvmDevice );

            isVGdeactivated = m_core->isVGdeactivated( lvmDevice );

            if ( isVGdeactivated )
                m_ui->revertButton->setEnabled( true );
        }
    }

    m_ui->createButton->setEnabled( create );
    m_ui->editButton->setEnabled( edit );
    m_ui->deleteButton->setEnabled( del );
    m_ui->newPartitionTableButton->setEnabled( createTable );
    m_ui->resizeVolumeGroupButton->setEnabled( currentDeviceIsVG && !isVGdeactivated );
    m_ui->deactivateVolumeGroupButton->setEnabled( currentDeviceIsVG && isDeactivable && !isVGdeactivated );
    m_ui->removeVolumeGroupButton->setEnabled( currentDeviceIsVG && isRemovable );
}
コード例 #17
0
	void ContactListDelegate::DrawCategory (QPainter *painter,
			QStyleOptionViewItemV4 o, const QModelIndex& index) const
	{
		const QRect& r = o.rect;

		QStyle *style = o.widget ?
				o.widget->style () :
				QApplication::style ();

		style->drawPrimitive (HighlightGroups_ ? QStyle::PE_PanelButtonCommand : QStyle::PE_PanelItemViewRow,
				&o, painter, o.widget);

		const int unread = index.data (Core::CLRUnreadMsgCount).toInt ();
		if (unread)
		{
			painter->save ();

			const QString& text = QString (" %1 :: ").arg (unread);

			QFont unreadFont = o.font;
			unreadFont.setBold (true);

			int unreadSpace = CPadding + QFontMetrics (unreadFont).width (text);

			painter->setFont (unreadFont);
			painter->drawText (r.left () + CPadding, r.top () + CPadding,
					unreadSpace, r.height () - 2 * CPadding,
					Qt::AlignVCenter | Qt::AlignLeft,
					text);

			painter->restore ();

			o.rect.setLeft (unreadSpace + o.rect.left ());
		}

		QStyledItemDelegate::paint (painter, o, index);

		o.state &= ~(QStyle::State_Selected | QStyle::State_MouseOver);

		const int textWidth = o.fontMetrics.width (index.data ().value<QString> () + " ");
		const int rem = r.width () - textWidth;

		const int visibleCount = index.model ()->rowCount (index);

		const QAbstractItemModel *model = index.model ();
		QModelIndex sourceIndex = index;
		while (const QAbstractProxyModel *proxyModel = qobject_cast<const QAbstractProxyModel*> (model))
		{
			model = proxyModel->sourceModel ();
			sourceIndex = proxyModel->mapToSource (sourceIndex);
		}

		const QString& str = QString (" %1/%2 ")
				.arg (visibleCount)
				.arg (model->rowCount (sourceIndex));

		painter->save ();

		painter->setRenderHints (QPainter::HighQualityAntialiasing | QPainter::Antialiasing);

		if (rem >= o.fontMetrics.width (str))
		{
			if (o.state & QStyle::State_Selected)
				painter->setPen (o.palette.color (QPalette::HighlightedText));

			QFont font = painter->font ();
			font.setItalic (true);
			painter->setFont (font);
			const QRect numRect (r.left () + textWidth - 1, r.top () + CPadding,
					rem - 1, r.height () - 2 * CPadding);
			painter->drawText (numRect, Qt::AlignVCenter | Qt::AlignRight, str);
		}

		painter->restore ();
	}
コード例 #18
0
ファイル: rawdelegate.cpp プロジェクト: TiKunze/mne-cpp
void RawDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    switch(index.column()) {
    case 0: { //chnames
        painter->save();

        painter->rotate(-90);
        painter->drawText(QRectF(-option.rect.y()-m_dPlotHeight,0,m_dPlotHeight,20),Qt::AlignCenter,index.model()->data(index,Qt::DisplayRole).toString());

        painter->restore();
        break;
    }
    case 1: { //data plot
        painter->save();

        //draw special background when channel is marked as bad
        QVariant v = index.model()->data(index,Qt::BackgroundRole);
        if(v.canConvert<QBrush>() && !(option.state & QStyle::State_Selected)) {
            QPointF oldBO = painter->brushOrigin();
            painter->setBrushOrigin(option.rect.topLeft());
            painter->fillRect(option.rect, qvariant_cast<QBrush>(v));
            painter->setBrushOrigin(oldBO);
        }

        //Highlight selected channels
        if(option.state & QStyle::State_Selected) {
            QPointF oldBO = painter->brushOrigin();
            painter->setBrushOrigin(option.rect.topLeft());
            painter->fillRect(option.rect, option.palette.highlight());
            painter->setBrushOrigin(oldBO);
        }

        //Get data
        QVariant variant = index.model()->data(index,Qt::DisplayRole);
        QList<RowVectorPair> listPairs = variant.value<QList<RowVectorPair> >();
        const RawModel* t_rawModel = (static_cast<const RawModel*>(index.model()));

        QPainterPath path(QPointF(option.rect.x()+t_rawModel->relFiffCursor()-1,option.rect.y()));

        //Plot grid
        painter->setRenderHint(QPainter::Antialiasing, false);
        createGridPath(path,listPairs);

        painter->save();
        QPen pen;
        pen.setStyle(Qt::DotLine);
        pen.setWidthF(0.5);
        painter->setPen(pen);
        painter->drawPath(path);
        painter->restore();

        //Plot data path
        path = QPainterPath(QPointF(option.rect.x()+t_rawModel->relFiffCursor(),option.rect.y()));
        createPlotPath(index,path,listPairs);

        painter->translate(0,m_dPlotHeight/2);

        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->drawPath(path);

        painter->restore();
        break;
    }
    }

}
コード例 #19
0
ファイル: ctkDICOMDatasetView.cpp プロジェクト: jhnstrk/CTK
// -------------------------------------------------------------------------
void ctkDICOMDatasetViewPrivate::setImage(const QModelIndex &imageIndex, bool defaultIntensity){
    Q_Q(ctkDICOMDatasetView);

    ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(imageIndex.model()));

    if(model){
        QModelIndex seriesIndex = imageIndex.parent();
        QModelIndex studyIndex = seriesIndex.parent();

        QString dicomPath = this->DatabaseDirectory;
        dicomPath.append("/dicom/").append(model->data(studyIndex ,ctkDICOMModel::UIDRole).toString());
        dicomPath.append("/").append(model->data(seriesIndex ,ctkDICOMModel::UIDRole).toString());
        dicomPath.append("/").append(model->data(imageIndex ,ctkDICOMModel::UIDRole).toString());

        if (QFile(dicomPath).exists()){
          DicomImage dcmImage(  QDir::toNativeSeparators(dicomPath).toStdString().c_str() );

            q->clearImages();
            q->addImage(dcmImage, defaultIntensity);
            this->CurrentImageIndex = imageIndex;

            q->emitImageDisplayedSignal(imageIndex.row(), model->rowCount(seriesIndex));
        }else{
            q->clearImages();
        }
    }
}
コード例 #20
0
ファイル: vlc_model.cpp プロジェクト: Annovae/vlc
QString VLCModel::getMeta( const QModelIndex & index, int meta )
{
    return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
        data().toString();
}
コード例 #21
0
ファイル: ctkDICOMDatasetView.cpp プロジェクト: jhnstrk/CTK
// -------------------------------------------------------------------------
void ctkDICOMDatasetViewPrivate::onImageModelSelected(const QModelIndex &index){
    Q_Q(ctkDICOMDatasetView);

    ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(index.model()));

    if(model){
        QModelIndex imageIndex = index;

        if(index.parent() == this->CurrentImageIndex.parent()){
            this->setImage(imageIndex, false);
        }else{
            this->setImage(imageIndex, true);
        }
    }else{
        q->clearImages();
    }
}
コード例 #22
0
inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const
{
    Q_ASSERT(index.isValid());
    Q_ASSERT(index.model() == nameFilterModel);
    return nameFilterModel->mapFromSource(index);
}
コード例 #23
0
ファイル: ctkDICOMDatasetView.cpp プロジェクト: jhnstrk/CTK
// -------------------------------------------------------------------------
void ctkDICOMDatasetView::displayImage(int imageIndex){
  Q_D(ctkDICOMDatasetView);

  if(d->CurrentImageIndex.isValid())
    {
      QModelIndex seriesIndex = d->CurrentImageIndex.parent();
      ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(seriesIndex.model()));

      if(model)
        {
          if(imageIndex >= 0 && imageIndex < model->rowCount(seriesIndex))
            {
            this->onModelSelected(model->index(imageIndex, 0, seriesIndex));
            }
          else
            {
            logger.debug("out of index");
            }
        }
    }
}
コード例 #24
0
ファイル: modeltest.cpp プロジェクト: KDE/krename
/*!
    Called from the parent() test.

    A model that returns an index of parent X should also return X when asking
    for the parent of the index.

    This recursive function does pretty extensive testing on the whole model in an
    effort to catch edge cases.

    This function assumes that rowCount(), columnCount() and index() already work.
    If they have a bug it will point it out, but the above tests should have already
    found the basic bugs because it is easier to figure out the problem in
    those tests then this one.
 */
void ModelTest::checkChildren(const QModelIndex &parent, int currentDepth)
{
    // First just try walking back up the tree.
    QModelIndex p = parent;
    while (p.isValid()) {
        p = p.parent();
    }

    // For models that are dynamically populated
    if (model->canFetchMore(parent)) {
        fetchingMore = true;
        model->fetchMore(parent);
        fetchingMore = false;
    }

    int rows = model->rowCount(parent);
    int columns = model->columnCount(parent);

    if (rows > 0) {
        Q_ASSERT(model->hasChildren(parent));
    }

    // Some further testing against rows(), columns(), and hasChildren()
    Q_ASSERT(rows >= 0);
    Q_ASSERT(columns >= 0);
    if (rows > 0) {
        Q_ASSERT(model->hasChildren(parent) == true);
    }

    //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
    //         << "columns:" << columns << "parent column:" << parent.column();

    Q_ASSERT(model->hasIndex(rows + 1, 0, parent) == false);
    for (int r = 0; r < rows; ++r) {
        if (model->canFetchMore(parent)) {
            fetchingMore = true;
            model->fetchMore(parent);
            fetchingMore = false;
        }
        Q_ASSERT(model->hasIndex(r, columns + 1, parent) == false);
        for (int c = 0; c < columns; ++c) {
            Q_ASSERT(model->hasIndex(r, c, parent) == true);
            QModelIndex index = model->index(r, c, parent);
            // rowCount() and columnCount() said that it existed...
            Q_ASSERT(index.isValid() == true);

            // index() should always return the same index when called twice in a row
            QModelIndex modifiedIndex = model->index(r, c, parent);
            Q_ASSERT(index == modifiedIndex);

            // Make sure we get the same index if we request it twice in a row
            QModelIndex a = model->index(r, c, parent);
            QModelIndex b = model->index(r, c, parent);
            Q_ASSERT(a == b);

            // Some basic checking on the index that is returned
            Q_ASSERT(index.model() == model);
            Q_ASSERT(index.row() == r);
            Q_ASSERT(index.column() == c);
            // While you can technically return a QVariant usually this is a sign
            // of an bug in data()  Disable if this really is ok in your model.
            Q_ASSERT(model->data(index, Qt::DisplayRole).isValid() == true);

            // If the next test fails here is some somewhat useful debug you play with.
            /*
            if (model->parent(index) != parent) {
                qDebug() << r << c << currentDepth << model->data(index).toString()
                         << model->data(parent).toString();
                qDebug() << index << parent << model->parent(index);
                // And a view that you can even use to show the model.
                //QTreeView view;
                //view.setModel(model);
                //view.show();
            }*/

            // Check that we can get back our real parent.
            Q_ASSERT(model->parent(index) == parent);

            // recursively go down the children
            if (model->hasChildren(index) && currentDepth < 10) {
                //qDebug() << r << c << "has children" << model->rowCount(index);
                checkChildren(index, ++currentDepth);
            }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/

            // make sure that after testing the children that the index doesn't change.
            QModelIndex newerIndex = model->index(r, c, parent);
            Q_ASSERT(index == newerIndex);
        }
    }
}
コード例 #25
0
/*!
    \reimp
 */
bool QIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
{
    Q_ASSERT(parent.isValid() ? parent.model() == this : true);
    Q_D(QIdentityProxyModel);
    return d->model->dropMimeData(data, action, row, column, mapToSource(parent));
}
コード例 #26
0
/*! Paints the gantt item \a idx using \a painter and \a opt
 */
void ItemDelegate::paintGanttItem( QPainter* painter,
                                   const StyleOptionGanttItem& opt,
                                   const QModelIndex& idx )
{
    if ( !idx.isValid() ) return;
    const ItemType typ = static_cast<ItemType>( idx.model()->data( idx, ItemTypeRole ).toInt() );
    const QString& txt = opt.text;
    QRectF itemRect = opt.itemRect;
    QRectF boundingRect = opt.boundingRect;
    boundingRect.setY( itemRect.y() );
    boundingRect.setHeight( itemRect.height() );
    //qDebug() << "itemRect="<<itemRect<<", boundingRect="<<boundingRect;

    painter->save();

    QPen pen = defaultPen( typ );
    if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
    painter->setPen( pen );
    painter->setBrush( defaultBrush( typ ) );

    qreal pw = painter->pen().width()/2.;
    switch( typ ) {
    case TypeTask:
        if ( itemRect.isValid() ) {
            // TODO
            qreal pw = painter->pen().width()/2.;
            pw-=1;
            QRectF r = itemRect;
            r.translate( 0., r.height()/6. );
            r.setHeight( 2.*r.height()/3. );
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawRect( r );
            bool ok;
            qreal completion = idx.model()->data( idx, KDGantt::TaskCompletionRole ).toDouble( &ok );
            if ( ok ) {
                qreal h = r.height();
                QRectF cr( r.x(), r.y()+h/4. + 1,
                           r.width()*completion/100., h/2. - 2 );
                painter->fillRect( cr, painter->pen().brush() );
            }
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta, txt );
        }
        break;
    case TypeSummary:
        if ( opt.itemRect.isValid() ) {
            // TODO
            pw-=1;
            const QRectF r = QRectF( opt.itemRect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal deltaY = r.height()/2.;
            const qreal deltaX = qMin( r.width()/qreal(2), deltaY );
            path.moveTo( r.topLeft() );
            path.lineTo( r.topRight() );
            path.lineTo( QPointF( r.right(), r.top() + 2.*deltaY ) );
            //path.lineTo( QPointF( r.right()-3./2.*delta, r.top() + delta ) );
            path.quadTo( QPointF( r.right()-.5*deltaX, r.top() + deltaY ), QPointF( r.right()-2.*deltaX, r.top() + deltaY ) );
            //path.lineTo( QPointF( r.left()+3./2.*delta, r.top() + delta ) );
            path.lineTo( QPointF( r.left() + 2.*deltaX, r.top() + deltaY ) );
            path.quadTo( QPointF( r.left()+.5*deltaX, r.top() + deltaY ), QPointF( r.left(), r.top() + 2.*deltaY ) );
            path.closeSubpath();
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    case TypeEvent: /* TODO */
        //qDebug() << opt.boundingRect << opt.itemRect;
        if ( opt.boundingRect.isValid() ) {
            const qreal pw = painter->pen().width() / 2. - 1;
            const QRectF r = QRectF( opt.rect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal delta = static_cast< int >( r.height() / 2 );
            path.moveTo( delta, 0. );
            path.lineTo( 2.*delta, delta );
            path.lineTo( delta, 2.*delta );
            path.lineTo( 0., delta );
            path.closeSubpath();
            painter->save();
            painter->translate( r.topLeft() );
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    default:
        break;
    }
    painter->restore();
}
コード例 #27
0
/*!
    \reimp
 */
bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
{
    Q_ASSERT(parent.isValid() ? parent.model() == this : true);
    Q_D(QIdentityProxyModel);
    return d->model->removeRows(row, count, mapToSource(parent));
}
コード例 #28
0
ファイル: pagewidget.cpp プロジェクト: CDrummond/carbon
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
        if (!index.isValid()) {
            return;
        }
        bool mouseOver = option.state & QStyle::State_MouseOver;
        bool gtk = mouseOver && qApp->style()->inherits("QGtkStyle");
        bool selected = option.state & QStyle::State_Selected;
        bool drawBgnd = true;

        if (!underMouse) {
            if (mouseOver && !selected) {
                drawBgnd = false;
            }
            mouseOver = false;
        }

        const QString text = index.model()->data(index, Qt::DisplayRole).toString();
        const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>();
        const QPixmap pixmap = icon.pixmap(iconSize, iconSize);

        QFontMetrics fm = painter->fontMetrics();
        int wp = pixmap.width();
        int hp = pixmap.height();

        QTextLayout iconTextLayout(text, option.font);
        QTextOption textOption(Qt::AlignHCenter);
        iconTextLayout.setTextOption(textOption);
        int maxWidth = qMax(3 * wp, 8 * fm.height());
        layoutText(&iconTextLayout, maxWidth);

        QPen pen = painter->pen();
        QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
                                  ? QPalette::Normal : QPalette::Disabled;
        if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
            cg = QPalette::Inactive;
        }

        QStyleOptionViewItem opt(option);
        opt.showDecorationSelected = true;
        QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

        if (drawBgnd) {
            if (mouseOver && gtk) {
                painter->save();
                opt.state |= QStyle::State_Selected;
                painter->setOpacity(selected ? 0.75 : 0.25);
            }
            style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
            if (mouseOver && gtk) {
                painter->restore();
            }
        }

        if (selected) {
            painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
        } else {
            painter->setPen(option.palette.color(cg, QPalette::Text));
        }

        painter->drawPixmap(option.rect.x() + (option.rect.width() / 2) - (wp / 2), option.rect.y() + 5, pixmap);
        if (!text.isEmpty()) {
            iconTextLayout.draw(painter, QPoint(option.rect.x() + (option.rect.width() / 2) - (maxWidth / 2), option.rect.y() + hp + 7));
        }
        painter->setPen(pen);
        drawFocus(painter, option, option.rect);
    }
コード例 #29
0
void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
    Q_ASSERT(parent.isValid() ? parent.model() == model : true);
    Q_Q(QIdentityProxyModel);
    q->beginRemoveRows(q->mapFromSource(parent), start, end);
}
コード例 #30
0
void RealTimeMultiSampleArrayDelegate::createPlotPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, QPointF &ellipsePos, QString &amplitude, RowVectorPair &data) const
{
    const RealTimeMultiSampleArrayModel* t_pModel = static_cast<const RealTimeMultiSampleArrayModel*>(index.model());

    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = t_pModel->getKind(index.row());
    float fMaxValue = 1e-9f;

    switch(kind) {
        case FIFFV_MEG_CH: {
            qint32 unit =t_pModel->getUnit(index.row());
            if(unit == FIFF_UNIT_T_M) { //gradiometers
                fMaxValue = 1e-10f;
                if(t_pModel->getScaling().contains(FIFF_UNIT_T_M))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T_M];
            }
            else if(unit == FIFF_UNIT_T) //magnetometers
            {
                fMaxValue = 1e-11f;

                //TODO: Debug this
//                if(t_pModel->getCoil(index.row()) == FIFFV_COIL_BABY_MAG)
//                    fMaxValue = 1e-11f;
//                else
//                    fMaxValue = 1e-11f;

                if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                    fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            }
            break;
        }

        case FIFFV_REF_MEG_CH: {  /*11/04/14 Added by Limin: MEG reference channel */
            fMaxValue = 1e-11f;
            if(t_pModel->getScaling().contains(FIFF_UNIT_T))
                fMaxValue = t_pModel->getScaling()[FIFF_UNIT_T];
            break;
        }
        case FIFFV_EEG_CH: {
            fMaxValue = 1e-4f;
            if(t_pModel->getScaling().contains(FIFFV_EEG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EEG_CH];
            break;
        }
        case FIFFV_EOG_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_EOG_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_EOG_CH];
            break;
        }
        case FIFFV_STIM_CH: {
            fMaxValue = 5;
            if(t_pModel->getScaling().contains(FIFFV_STIM_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_STIM_CH];
            break;
        }
        case FIFFV_MISC_CH: {
            fMaxValue = 1e-3f;
            if(t_pModel->getScaling().contains(FIFFV_MISC_CH))
                fMaxValue = t_pModel->getScaling()[FIFFV_MISC_CH];
            break;
        }
    }

    float fValue;
    float fScaleY = option.rect.height()/(2*fMaxValue);

    float y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    float fDx = ((float)option.rect.width()) / t_pModel->getMaxSamples();

    int currentSampleIndex = t_pModel->getCurrentSampleIndex();
    float lastFirstValue = t_pModel->getLastBlockFirstValue(index.row());

    //Move to initial starting point
    if(data.second > 0)
    {
//        float val = data[0];
        fValue = 0;//(val-data[0])*fScaleY;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x());

        path.moveTo(qSamplePosition);
    }

    float val;

    for(qint32 j=0; j < data.second; ++j)
    {
        if(j<currentSampleIndex)
            val = *(data.first+j) - *(data.first); //remove first sample data[0] as offset
        else
            val = *(data.first+j) - lastFirstValue; //do not remove first sample data[0] as offset because this is the last data part

        fValue = val*fScaleY;
        //qDebug()<<"val"<<val<<"fScaleY"<<fScaleY<<"fValue"<<fValue;

        float newY = y_base-fValue;//Reverse direction -> plot the right way

        qSamplePosition.setY(newY);
        qSamplePosition.setX(path.currentPosition().x()+fDx);
        path.lineTo(qSamplePosition);

        //Create ellipse position
        if(j == (qint32)(m_markerPosition.x()/fDx)) {
            ellipsePos.setX(path.currentPosition().x()+fDx);
            ellipsePos.setY(newY/*+(option.rect.height()/2)*/);

            amplitude = QString::number(*(data.first+j));
        }
    }
}