[Rinside-commits] r217 - in pkg: . inst inst/examples/qt

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 5 03:44:12 CET 2011


Author: edd
Date: 2011-12-05 03:44:10 +0100 (Mon, 05 Dec 2011)
New Revision: 217

Modified:
   pkg/ChangeLog
   pkg/cleanup
   pkg/inst/NEWS
   pkg/inst/examples/qt/qtdensity.cpp
   pkg/inst/examples/qt/qtdensity.h
Log:
qtdensity now uses svg() device in R


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2011-12-04 15:05:08 UTC (rev 216)
+++ pkg/ChangeLog	2011-12-05 02:44:10 UTC (rev 217)
@@ -1,3 +1,12 @@
+2011-12-04  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/examples/qt/qtdensity.cpp: Default to svg creation via the
+	svg() now in base R, ie remove both the test for cairoDevice and the
+	fallback use of png graphics code; we still need to filter the svg file
+	* inst/examples/qt/qtdensity.h: adjust accordingly
+
+	* cleanup: Clean qt and wt example directories too
+
 2011-11-24  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/wt: New example directory 'wt' providing a Webtoolkit

Modified: pkg/cleanup
===================================================================
--- pkg/cleanup	2011-12-04 15:05:08 UTC (rev 216)
+++ pkg/cleanup	2011-12-05 02:44:10 UTC (rev 217)
@@ -4,4 +4,6 @@
 
 cd inst/examples/standard && make clean && cd -
 cd inst/examples/mpi && make clean && cd -
+cd inst/examples/qt && make clean && cd -
+cd inst/examples/wt && make clean && cd -
 

Modified: pkg/inst/NEWS
===================================================================
--- pkg/inst/NEWS	2011-12-04 15:05:08 UTC (rev 216)
+++ pkg/inst/NEWS	2011-12-05 02:44:10 UTC (rev 217)
@@ -3,6 +3,9 @@
    o    New example embedding R inside a Wt (aka Webtoolkit, pronounced 
         'witty') application, mirroring the previous Qt application
 
+   o    Qt example qtdensity now uses the new svg() device in base R; removed
+        test for cairoDevice package as well as fallback png code
+
    o    Very minor fix to qmake.pro file for Qt app correcting link order
 
 0.2.4   2011-04-24
@@ -70,9 +73,9 @@
 
 0.2.1	2010-01-06
 
-   o    Startup mpw defaults to FALSE, no longer call Rf_KillAllDevices
+   o    Startup now defaults to FALSE, no longer call Rf_KillAllDevices
 
-   o    Some minor build anc code fixes for Windows
+   o    Some minor build and code fixes for Windows
 
 0.2.0   2009-12-20
 

Modified: pkg/inst/examples/qt/qtdensity.cpp
===================================================================
--- pkg/inst/examples/qt/qtdensity.cpp	2011-12-04 15:05:08 UTC (rev 216)
+++ pkg/inst/examples/qt/qtdensity.cpp	2011-12-05 02:44:10 UTC (rev 217)
@@ -17,10 +17,6 @@
     m_R["bw"] = m_bw;           // pass bandwidth to R, and have R compute a temp.file name
     m_tempfile = QString::fromStdString(Rcpp::as<std::string>(m_R.parseEval("tfile <- tempfile()")));
     m_svgfile = QString::fromStdString(Rcpp::as<std::string>(m_R.parseEval("sfile <- tempfile()")));
-    m_use_svg = m_R.parseEval("require(cairoDevice)");
-    if (!m_use_svg) {
-        std::cerr << "Consider installing the 'cairoDevice' package from CRAN to create SVG graphics." << std::endl;
-    }
     setupDisplay();
 }
 
@@ -68,15 +64,7 @@
     kernelGroup->addButton(radio5, 4);
     QObject::connect(kernelGroup, SIGNAL(buttonClicked(int)), this, SLOT(getKernel(int)));
 
-    if (m_use_svg) {            // svg case
-        m_svg = new QSvgWidget();
-    } else {                    // png default
-        m_imageLabel = new QLabel;
-        m_imageLabel->setBackgroundRole(QPalette::Base);
-        m_imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
-        m_imageLabel->setScaledContents(true);
-        m_image = new QImage(m_tempfile);
-    }
+    m_svg = new QSvgWidget();
     runRandomDataCmd();         // also calls plot()
 
     QGroupBox *estimationBox = new QGroupBox("Density estimation bandwidth (scaled by 100)");
@@ -96,43 +84,26 @@
     upperlayout->addWidget(estimationBox);
 
     QHBoxLayout *lowerlayout = new QHBoxLayout;
-    if (m_use_svg) {
-        lowerlayout->addWidget(m_svg);
-    } else {
-        lowerlayout->addWidget(m_imageLabel);
-    }
+    lowerlayout->addWidget(m_svg);
 
     QVBoxLayout *outer = new QVBoxLayout;
     outer->addLayout(upperlayout);
     outer->addLayout(lowerlayout);
     window->setLayout(outer);
     window->show();
-    if (!m_use_svg) {
-        window->resize(650, 750);
-    }
 }
 
 void QtDensity::plot(void) {
     const char *kernelstrings[] = { "gaussian", "epanechnikov", "rectangular", "triangular", "cosine" };
     m_R["bw"] = m_bw;
     m_R["kernel"] = kernelstrings[m_kernel]; // that passes the string to R
-    std::string cmd0;
-    if (m_use_svg) {         // select device based on whether cairoDevice is available or not
-        cmd0 = "Cairo(width=6,height=6,pointsize=10,surface='svg',filename=tfile); ";
-    } else {
-        cmd0 = "png(filename=tfile,width=600,height=600);";
-    }
+    std::string cmd0 = "svg(width=6,height=6,pointsize=10,filename=tfile); ";
     std::string cmd1 = "plot(density(y, bw=bw/100, kernel=kernel), xlim=range(y)+c(-2,2), main=\"Kernel: ";
     std::string cmd2 = "\"); points(y, rep(0, length(y)), pch=16, col=rgb(0,0,0,1/4));  dev.off()";
     std::string cmd = cmd0 + cmd1 + kernelstrings[m_kernel] + cmd2; // stick the selected kernel in the middle
     m_R.parseEvalQ(cmd);
-    if (m_use_svg) {
-        filterFile();           // we need to simplify the svg file for display by Qt 
-        m_svg->load(m_svgfile);
-    } else {
-        m_image->load(m_tempfile);
-        m_imageLabel->setPixmap(QPixmap::fromImage(*m_image));
-    }
+    filterFile();           	// we need to simplify the svg file for display by Qt 
+    m_svg->load(m_svgfile);
 }
 
 void QtDensity::getBandwidth(int bw) {
@@ -162,7 +133,6 @@
 void QtDensity::filterFile() {
     // cairoDevice creates richer SVG than Qt can display
     // but per Michaele Lawrence, a simple trick is to s/symbol/g/ which we do here
-
     QFile infile(m_tempfile);
     infile.open(QFile::ReadOnly);
     QFile outfile(m_svgfile);

Modified: pkg/inst/examples/qt/qtdensity.h
===================================================================
--- pkg/inst/examples/qt/qtdensity.h	2011-12-04 15:05:08 UTC (rev 216)
+++ pkg/inst/examples/qt/qtdensity.h	2011-12-05 02:44:10 UTC (rev 217)
@@ -37,16 +37,11 @@
     void filterFile(void);      // modify the richer SVG produced by R
 
     QSvgWidget *m_svg;          // the SVG device
-
-    QLabel *m_imageLabel;       // image display in non-SVG case
-    QImage *m_image;
-
     RInside & m_R;              // reference to the R instance passed to constructor
     QString m_tempfile;         // name of file used by R for plots
     QString m_svgfile;          // another temp file, this time from Qt
     int m_bw, m_kernel;         // parameters used to estimate the density
     QString m_cmd;              // random draw command string
-    bool m_use_svg;             // create SVG if cairoDevice can be loaded
 };
 
 #endif



More information about the Rinside-commits mailing list