Skip to content

Commit

Permalink
Complete backport of stem plots from today's QtiPlot. Re #2654.
Browse files Browse the repository at this point in the history
They can now be created from tables via the gui as well.
Also added back the MdiSubWindow::print() method to Note. Re #4341.
  • Loading branch information
RussellTaylor committed Dec 16, 2011
1 parent 77e118f commit b2a1d26
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,8 @@ void ApplicationWindow::plotMenuAboutToShow()
statMenu->addAction(actionBoxPlot);
statMenu->addAction(actionPlotHistogram);
statMenu->addAction(actionPlotStackedHistograms);
statMenu->insertSeparator();
statMenu->addAction(actionStemPlot);

QMenu *panelsMenu = plot2DMenu->addMenu (tr("Pa&nel"));
panelsMenu->addAction(actionPlot2VerticalLayers);
Expand Down Expand Up @@ -1982,6 +1984,35 @@ QString ApplicationWindow::stemPlot(Table *t, const QString& colName, int power,
return result;
}

Note * ApplicationWindow::newStemPlot()
{
Table *t = (Table *)activeWindow(TableWindow);
if (!t)
return NULL;

int ts = t->table()->currentSelection();
if (ts < 0)
return NULL;

Note *n = newNote();
if (!n)
return NULL;
n->hide();

QStringList lst = t->selectedColumns();
if (lst.isEmpty()){
Q3TableSelection sel = t->table()->selection(ts);
for (int i = sel.leftCol(); i <= sel.rightCol(); i++)
n->setText(stemPlot(t, t->colName(i), 1001, sel.topRow() + 1, sel.bottomRow() + 1) + "\n");
} else {
for (int i = 0; i < lst.count(); i++)
n->setText(stemPlot(t, lst[i], 1001) + "\n");
}

n->show();
return n;
}

void ApplicationWindow::renameListViewItem(const QString& oldName,const QString& newName)
{
Q3ListViewItem *it=lv->findItem (oldName,0, Q3ListView::ExactMatch | Qt::CaseSensitive );
Expand Down Expand Up @@ -6581,6 +6612,8 @@ void ApplicationWindow::showColMenu(int c)
stat.addAction(actionBoxPlot);
stat.addAction(QIcon(getQPixmap("histogram_xpm")),tr("&Histogram"), this, SLOT(plotHistogram()));
stat.addAction(QIcon(getQPixmap("stacked_hist_xpm")),tr("&Stacked Histograms"), this, SLOT(plotStackedHistograms()));
stat.insertSeparator();
stat.addAction(actionStemPlot);
stat.setTitle(tr("Statistical &Graphs"));
plot.addMenu(&stat);

Expand Down Expand Up @@ -6699,6 +6732,8 @@ void ApplicationWindow::showColMenu(int c)
stat.addAction(actionBoxPlot);
stat.addAction(QIcon(getQPixmap("histogram_xpm")),tr("&Histogram"), this, SLOT(plotHistogram()));
stat.addAction(QIcon(getQPixmap("stacked_hist_xpm")),tr("&Stacked Histograms"), this, SLOT(plotStackedHistograms()));
stat.insertSeparator();
stat.addAction(actionStemPlot);
stat.setTitle(tr("Statistical &Graphs"));
plot.addMenu(&stat);

Expand Down Expand Up @@ -12443,6 +12478,9 @@ void ApplicationWindow::createActions()
actionPlotStackedHistograms = new QAction(QIcon(getQPixmap("stacked_hist_xpm")), tr("&Stacked Histogram"), this);
connect(actionPlotStackedHistograms, SIGNAL(activated()), this, SLOT(plotStackedHistograms()));

actionStemPlot = new QAction(QIcon(":/leaf.png"), tr("Stem-and-&Leaf Plot"), this);
connect(actionStemPlot, SIGNAL(activated()), this, SLOT(newStemPlot()));

actionPlot2VerticalLayers = new QAction(QIcon(getQPixmap("panel_v2_xpm")), tr("&Vertical 2 Layers"), this);
connect(actionPlot2VerticalLayers, SIGNAL(activated()), this, SLOT(plot2VerticalLayers()));

Expand Down Expand Up @@ -13286,6 +13324,9 @@ void ApplicationWindow::translateActionsStrings()
actionPlot4Layers->setMenuText(tr("&4 Layers"));
actionPlotStackedLayers->setMenuText(tr("&Stacked Layers"));

actionStemPlot->setMenuText(tr("Stem-and-&Leaf Plot"));
actionStemPlot->setToolTip(tr("Stem-and-Leaf Plot"));

actionPlot3DRibbon->setMenuText(tr("&Ribbon"));
actionPlot3DRibbon->setToolTip(tr("Plot 3D ribbon"));

Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ public slots:

/// Create a stem plot from a table and return a string representation of it
QString stemPlot(Table *t = 0, const QString& colName = QString(), int power = 0, int startRow = 0, int endRow = -1);
Note *newStemPlot();

//! Check whether a table is valid for a 3D plot and display an appropriate error if not
bool validFor3DPlot(Table *table);
Expand Down Expand Up @@ -1327,7 +1328,7 @@ public slots:
QAction *actionShowConsole;
QAction *actionSwapColumns, *actionMoveColRight, *actionMoveColLeft, *actionMoveColFirst, *actionMoveColLast;
QAction *actionExportGraph, *actionExportAllGraphs, *actionPrint, *actionPrintAllPlots, *actionShowExportASCIIDialog;
QAction *actionExportPDF, *actionReadOnlyCol;
QAction *actionExportPDF, *actionReadOnlyCol, *actionStemPlot;
QAction *actionCloseAllWindows, *actionClearLogInfo, *actionClearConsole, *actionShowPlotWizard, *actionShowConfigureDialog;
QAction *actionShowCurvesDialog, *actionAddErrorBars, *actionRemoveErrorBars, *actionAddFunctionCurve, *actionUnzoom, *actionNewLegend, *actionAddImage, *actionAddText;
QAction *actionPlotL, *actionPlotP, *actionPlotLP, *actionPlotVerticalDropLines, *actionPlotSpline;
Expand Down
15 changes: 15 additions & 0 deletions Code/Mantid/MantidPlot/src/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
#include <Qsci/qsciprinter.h>
#include <QPrintDialog>
#include "MantidKernel/ConfigService.h"

Note::Note(const QString& label, ApplicationWindow* parent, const QString& name, Qt::WFlags f)
Expand Down Expand Up @@ -88,6 +90,19 @@ void Note::restore(const QStringList& data)
te->append((*line++)+"\n"); //Mantid - changes for QScintilla
}

void Note::print()
{
QsciPrinter printer(QPrinter::HighResolution);
printer.setColorMode(QPrinter::GrayScale);
printer.setOutputFormat(QPrinter::PostScriptFormat);
QPrintDialog printDialog(&printer);
printDialog.setWindowTitle("MantidPlot - Print Script");
if (printDialog.exec() == QDialog::Accepted)
{
te->document()->print(&printer);
}
}

QString Note::exportASCII(const QString &filename)
{
QString filter;
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public slots:
QString text() { return te->text(); }
void setText(const QString &s) { te->setText(s); }

void print();
QString exportASCII(const QString &filename=QString::null);

private:
Expand Down

0 comments on commit b2a1d26

Please sign in to comment.