SEXP qt_qsetScene(SEXP rview, SEXP rscene) { // rview is new smoke-style, rscene is old-style (????) unwrapSmoke(rview, QGraphicsView)-> setScene(unwrapSmoke(rscene, QGraphicsScene)); return R_NilValue; }
extern "C" SEXP qt_qmocMethods(SEXP x) { const QMetaObject *meta = unwrapSmoke(x, QMetaObject); int n = meta->methodCount(); SEXP ans, ans_type, ans_signature, ans_return, ans_nargs; PROTECT(ans = allocVector(VECSXP, 4)); ans_type = allocVector(INTSXP, n); SET_VECTOR_ELT(ans, 0, ans_type); ans_signature = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 1, ans_signature); ans_return = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 2, ans_return); ans_nargs = allocVector(INTSXP, n); SET_VECTOR_ELT(ans, 3, ans_nargs); for (int i = 0; i < n; i++) { QMetaMethod metaMethod = meta->method(i); INTEGER(ans_type)[i] = metaMethod.methodType(); SET_STRING_ELT(ans_signature, i, mkChar(metaMethod.signature())); SET_STRING_ELT(ans_return, i, mkChar(metaMethod.typeName())); INTEGER(ans_nargs)[i] = metaMethod.parameterNames().size(); } UNPROTECT(1); return ans; }
extern "C" SEXP qt_qproperties(SEXP x) { const QMetaObject *meta = unwrapSmoke(x, QMetaObject); int n = meta->propertyCount(); SEXP ans, ans_type, ans_name, ans_readable, ans_writable; PROTECT(ans = allocVector(VECSXP, 4)); ans_name = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 0, ans_name); ans_type = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 1, ans_type); ans_readable = allocVector(LGLSXP, n); SET_VECTOR_ELT(ans, 2, ans_readable); ans_writable = allocVector(LGLSXP, n); SET_VECTOR_ELT(ans, 3, ans_writable); for (int i = 0; i < n; i++) { QMetaProperty metaProperty = meta->property(i); SET_STRING_ELT(ans_type, i, mkChar(metaProperty.typeName())); SET_STRING_ELT(ans_name, i, mkChar(metaProperty.name())); LOGICAL(ans_readable)[i] = metaProperty.isReadable(); LOGICAL(ans_writable)[i] = metaProperty.isWritable(); } UNPROTECT(1); return ans; }
// DOES NOT CREATE new QImage, only replaces. To create, use R wrapper suitably. SEXP qt_matrix2qimage_rgb(SEXP x, SEXP red, SEXP green, SEXP blue, SEXP alpha) { double *r, *g, *b, *a; QImage *img = unwrapSmoke(x, QImage); int i, j, w = img->width(), h = img->height(); r = REAL(red); g = REAL(green); b = REAL(blue); a = REAL(alpha); if (alpha == R_NilValue) { // no alpha channel for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { img->setPixel(i, j, qRgb((int) (r[i + j*w] * 255), (int) (g[i + j*w] * 255), (int) (b[i + j*w] * 255))); } } } else { for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { img->setPixel(i, j, qRgba((int) (r[i + j*w] * 255), (int) (g[i + j*w] * 255), (int) (b[i + j*w] * 255), (int) (a[i + j*w] * 255))); } } } return R_NilValue; }
SEXP qt_qsetDataFrame(SEXP rmodel, SEXP df, SEXP roles, SEXP rowHeader, SEXP colHeader) { DataFrameModel *model = static_cast<DataFrameModel *>(unwrapSmoke(rmodel, QAbstractTableModel)); model->setDataFrame(df, roles, rowHeader, colHeader); return R_NilValue; }
SEXP qt_qsetRSyntaxHighlighter(SEXP x) { QTextEdit *edit = unwrapSmoke(x, QTextEdit); RSyntaxHighlighter *highlighter = new RSyntaxHighlighter(edit->document()); highlighter->setActive(true); return R_NilValue; }
SEXP qt_qsetCursorPosition_QTextEdit(SEXP x, SEXP pos) { QTextEdit *te = unwrapSmoke(x, QTextEdit); QTextCursor tc = te->textCursor(); tc.setPosition(asInteger(pos)); te->setTextCursor(tc); return R_NilValue; }
SEXP qt_qdataFrameModel(SEXP rparent, SEXP useRoles, SEXP editable) { static Class *dataFrameModelClass = new NameOnlyClass("DataFrameModel", Class::fromName("QAbstractTableModel")); SmokeObject *so = SmokeObject::fromPtr(new DataFrameModel(unwrapSmoke(rparent, QObject), useRoles, editable), Class::fromName("QAbstractTableModel"), true); so->cast(dataFrameModelClass); return so->sexp(); }
SEXP qt_qsceneView(SEXP scene) { QGraphicsView *v = new QGraphicsView(unwrapSmoke(scene, QGraphicsScene), 0); v->setRenderHints(QPainter::TextAntialiasing); v->setInteractive(true); // v->setDragMode(QGraphicsView::RubberBandDrag); v->setDragMode(QGraphicsView::ScrollHandDrag); return wrapSmoke(v, QGraphicsView, true); }
// DOES NOT CREATE new QImage, only replaces. To create, use R wrapper suitably. SEXP qt_matrix2qimage_gray(SEXP x, SEXP gray) { QImage *img = unwrapSmoke(x, QImage); int i, j, col, w = img->width(), h = img->height(); double *g = REAL(gray); for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { col = (int) (g[i + j*w] * 255); img->setPixel(i, j, qRgb(col, col, col)); } } return R_NilValue; }
SEXP qt_qimage2matrix_gray(SEXP x) { SEXP ans, dim; double *ip; QImage *img = unwrapSmoke(x, QImage); dim = PROTECT(allocVector(INTSXP, 2)); int i, j, w = img->width(), h = img->height(); INTEGER(dim)[0] = w; INTEGER(dim)[1] = h; ans = PROTECT(allocVector(REALSXP, w * h)); setAttrib(ans, R_DimSymbol, dim); ip = REAL(ans); for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { ip[i + j*w] = 1.0 * qGray(img->pixel(i, j)) / 255.0; } } UNPROTECT(2); return ans; }
SEXP qt_qimage2matrix_rgb(SEXP x, SEXP alpha) { SEXP ans, dim; double *ip; QRgb prgb; QImage *img = unwrapSmoke(x, QImage); dim = PROTECT(allocVector(INTSXP, 3)); int i, j, components, w = img->width(), h = img->height(); if (asLogical(alpha)) components = 4; else components = 3; INTEGER(dim)[0] = w; INTEGER(dim)[1] = h; INTEGER(dim)[2] = components; ans = PROTECT(allocVector(REALSXP, w * h * components)); setAttrib(ans, R_DimSymbol, dim); ip = REAL(ans); if (components == 3) { // no alpha channel for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { prgb = img->pixel(i, j); ip[i + j*w] = 1.0 * qRed(prgb) / 255.0; ip[i + j*w + h*w] = 1.0 * qGreen(prgb) / 255.0; ip[i + j*w + 2*h*w] = 1.0 * qBlue(prgb) / 255.0; } } } else { for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { prgb = img->pixel(i, j); ip[i + j*w] = 1.0 * qRed(prgb) / 255.0; ip[i + j*w + h*w] = 1.0 * qGreen(prgb) / 255.0; ip[i + j*w + 2*h*w] = 1.0 * qBlue(prgb) / 255.0; ip[i + j*w + 3*h*w] = 1.0 * qAlpha(prgb) / 255.0; } } } UNPROTECT(2); return ans; }
bool MocProperty::write(SEXP obj, SEXP val) { QObject *qobj = unwrapSmoke(obj, QObject); return qobj->setProperty(name(), from_sexp<QVariant>(val)); }
SEXP qt_quseRoles(SEXP rmodel) { DataFrameModel *model = static_cast<DataFrameModel *>(unwrapSmoke(rmodel, QAbstractTableModel)); return model->useRoles(); }
SEXP qt_qeditable(SEXP rmodel) { DataFrameModel *model = static_cast<DataFrameModel *>(unwrapSmoke(rmodel, QAbstractTableModel)); return model->editable(); }
SEXP qt_coerce_QSignalSpy(SEXP sexp) { return to_sexp(unwrapSmoke(sexp, QSignalSpy)); }
SEXP MocProperty::read(SEXP obj) const { QObject *qobj = unwrapSmoke(obj, QObject); return to_sexp(qobj->property(name())); }