Beispiel #1
0
SEXP 
qt_qaddTab(SEXP x, SEXP tab, SEXP label, SEXP index) {
    int i = asInteger(index);
    if (i <= 0)
	unwrapQObject(x, QTabWidget)->addTab(unwrapQObject(tab, QWidget), sexp2qstring(label));
    else 
	unwrapQObject(x, QTabWidget)->insertTab(i - 1, unwrapQObject(tab, QWidget), sexp2qstring(label));
    return R_NilValue;
}
Beispiel #2
0
SEXP qt_qsetItemFlags_QGraphicsItem(SEXP x, SEXP flag, SEXP status)
{
    setItemFlag_helper(unwrapQGraphicsItem(x, QGraphicsItem), 
		       sexp2qstring(flag), 
		       (bool) asLogical(status));
    return R_NilValue;
}
Beispiel #3
0
SEXP qt_qsetTextItemInteraction(SEXP x, SEXP mode)
{
    QList<QGraphicsItem*> ilist = unwrapQObject(x, QGraphicsScene)->items();
    QGraphicsTextItem *textitem;
    QString smode = sexp2qstring(mode);
    if (smode == "none") {
	for (int i = 0; i < ilist.size(); ++i) {
	    textitem = qgraphicsitem_cast<QGraphicsTextItem *>(ilist[i]);
	    if (textitem)
		textitem->setTextInteractionFlags(Qt::NoTextInteraction);
	}
    }
    else if (smode == "editor") {
	for (int i = 0; i < ilist.size(); ++i) {
	    textitem = qgraphicsitem_cast<QGraphicsTextItem *>(ilist[i]);
	    if (textitem)
		textitem->setTextInteractionFlags(Qt::TextEditorInteraction);
	}
    }
    else if (smode == "browser") {
	for (int i = 0; i < ilist.size(); ++i) {
	    textitem = qgraphicsitem_cast<QGraphicsTextItem *>(ilist[i]);
	    if (textitem)
		textitem->setTextInteractionFlags(Qt::TextBrowserInteraction);
	}
    }
    return R_NilValue;
}
Beispiel #4
0
SEXP qt_qsetText_QGraphicsItem(SEXP item, SEXP label)
{
    QGraphicsItem *i = unwrapQGraphicsItem(item, QGraphicsItem);
    QGraphicsTextItem *textitem = qgraphicsitem_cast<QGraphicsTextItem *>(i);
    if (textitem)
	textitem->setHtml(sexp2qstring(label));
    return R_NilValue;
}
Beispiel #5
0
SEXP qt_qsetItemIndexMethod(SEXP s, SEXP method)
{
    if (sexp2qstring(method) == "none")
	unwrapQObject(s, QGraphicsScene)->setItemIndexMethod(QGraphicsScene::NoIndex);
    else 
	unwrapQObject(s, QGraphicsScene)->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
    return R_NilValue;
}
Beispiel #6
0
SEXP qt_qsetItemFlags_QGraphicsScene(SEXP x, SEXP flag, SEXP status)
{
    QList<QGraphicsItem*> ilist = unwrapQObject(x, QGraphicsScene)->items();
    bool bstatus = (bool) asLogical(status);
    QString sflag = sexp2qstring(flag);
    for (int i = 0; i < ilist.size(); ++i) {
	setItemFlag_helper(ilist[i], sflag, bstatus);
    }
    return R_NilValue;
}
Beispiel #7
0
SEXP qt_qsetToolTip_QGraphicsItem(SEXP item, SEXP s)
{
    unwrapQGraphicsItem(item, QGraphicsItem)->setToolTip(sexp2qstring(s));
    return R_NilValue;
}
Beispiel #8
0
SEXP 
qt_qsetText_QLineEdit(SEXP x, SEXP s) {
    unwrapQObject(x, QLineEdit)->setText(sexp2qstring(s));
    return R_NilValue;
}
Beispiel #9
0
SEXP 
qt_qcheckBox(SEXP label) {
    if (label == R_NilValue) return wrapQWidget(new QCheckBox(0));
    else return wrapQWidget(new QCheckBox(sexp2qstring(label), 0));
}
Beispiel #10
0
SEXP 
qt_qlineEdit(SEXP s) {
    QLineEdit *x = new QLineEdit();
    if (s != R_NilValue) x->setText(sexp2qstring(s));
    return wrapQWidget(x);
}
Beispiel #11
0
SEXP 
qt_qlabel(SEXP label) {
    return wrapQWidget(new QLabel(sexp2qstring(label), 0));
}
Beispiel #12
0
SEXP 
qt_qsetText_QAbstractButton(SEXP x, SEXP s) {
    unwrapQObject(x, QAbstractButton)->setText(sexp2qstring(s));
    return R_NilValue;
}
Beispiel #13
0
SEXP 
qt_qpushButton(SEXP s) {
    return wrapQWidget(new QPushButton(sexp2qstring(s)));
}
Beispiel #14
0
QVariant qvariant_from_sexp(SEXP rvalue, int index) {
  QVariant variant;
  if (index == -1) {
    /* If a particular element is not selected, then non-lists of
       length one are considered scalars. Otherwise, collections.
       Except for raw vectors, which are naturally QByteArrays.
    */
    if (TYPEOF(rvalue) == RAWSXP)
      return QVariant(from_sexp<QByteArray>(rvalue));
    else if (TYPEOF(rvalue) == VECSXP || length(rvalue) > 1) {
      SEXP rlist = coerceVector(rvalue, VECSXP);
      if (getAttrib(rvalue, R_NamesSymbol) != R_NilValue)
        variant = asQVariantOfType(rlist, QMetaType::QVariantMap);
      else variant = asQVariantOfType(rlist, QMetaType::QVariantList);
      return variant;
    }
    index = 0;
  }
  switch(TYPEOF(rvalue)) {
  case RAWSXP:
    variant = qVariantFromValue(RAW(rvalue)[index]);
    break;
  case LGLSXP:
    // Rprintf("Logical\n");
    // FIXME: by converting to 'bool' all NA become TRUE
    variant = QVariant((bool)LOGICAL(rvalue)[index]);
    break;
  case REALSXP:
    // Rprintf("Real\n");
    variant = QVariant(REAL(rvalue)[index]);
    break;
  case INTSXP:
    // Rprintf("Integer\n");
    {
      SEXP levels;
      if ((levels = getAttrib(rvalue, R_LevelsSymbol)) != R_NilValue) {
        int level = INTEGER(rvalue)[index];
        SEXP level_str = NA_STRING;
        /*Rprintf("getting level: %d\n", level);*/
        if (level != NA_INTEGER)
          level_str = STRING_ELT(levels, level - 1);
        variant = QVariant(sexp2qstring(level_str));
      } else variant = QVariant(INTEGER(rvalue)[index]);
      break;
    }
  case STRSXP:
    // Rprintf("String\n");
    variant = QVariant(sexp2qstring(STRING_ELT(rvalue, index)));
    break;
  case EXTPTRSXP:
    // Rprintf("External pointer\n");
    variant = qVariantFromValue(unwrapPointer(rvalue, void));
    break;
  case VECSXP:
    variant = from_sexp<QVariant>(VECTOR_ELT(rvalue, index));
    break;
  case ENVSXP: {
    SmokeObject *so = SmokeObject::fromSexp(rvalue);
    if (so->instanceOf("QWidget"))
      variant =
        qVariantFromValue(reinterpret_cast<QWidget *>(so->castPtr("QWidget")));
    else if (so->instanceOf("QObject"))
      variant =
        qVariantFromValue(reinterpret_cast<QObject *>(so->castPtr("QObject")));
    else {
      QMetaType::Type type = (QMetaType::Type) QMetaType::type(so->className());
      if (type)
        variant = asQVariantOfType(rvalue, type, false);
      else variant = qVariantFromValue(so->ptr());
    }
  }
    break;
  case NILSXP: // invalid QVariant
    break;
  default:
    error("Converting to QVariant: unhandled R type");
  }
  return variant;
}