Vespucci  1.0.0
mapviewer.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include "GUI/Display/mapviewer.h"
21 #include "ui_mapviewer.h"
22 #include "Global/vespucci.h"
23 #include "Global/global.h"
24 
31 MapViewer::MapViewer(MainWindow *parent, QStringList map_keys, QSharedPointer<VespucciWorkspace> ws):
32  QMainWindow(parent), ui(new Ui::MapViewer), map_keys_(map_keys)
33 
34 {
35  ui->setupUi(this);
36  workspace_ = ws;
37  name_ = map_keys.last();
38  directory_ = ws->directory_ptr();
39  ui->mapPlot->setBackground(palette().window());
40  statusbar_label_ = new QLabel("(0, 0, 0)");
41  ui->statusbar->addWidget(statusbar_label_);
42  connect(this, &MapViewer::RequestSpectrumPlot,
46  connect(ui->mapPlot, &MapPlot::SpectrumRequested,
48  connect(ui->mapPlot, &MapPlot::CoordinatesChanged,
50  parent->plot_viewer()->SetHoldCheckBoxChecked(true);
51  ui->mapPlot->setBackground(Qt::white);
52  ui->mapPlot->replot(QCustomPlot::rpImmediate);
53 }
54 
56 {
57  return ui->mapPlot;
58 }
59 
61 {
62  delete ui;
63 }
64 
70 void MapViewer::SpectrumRequested(size_t index)
71 {
72  emit RequestSpectrumPlot(map_keys_.first(),
73  map_keys_.last(),
74  index);
75 }
76 
77 void MapViewer::SetStatusbar(double x, double y, double z)
78 {
79  QString text = "(" + QString::number(x) + ", " +
80  QString::number(y) + ", " +
81  QString::number(z) + ")";
82  statusbar_label_->setText(text);
83 }
84 
89 void MapViewer::on_actionInterpolate_toggled(bool arg1)
90 {
91  workspace_->GetMap(map_keys_)->setInterpolate(arg1);
92 }
93 
97 void MapViewer::on_actionSave_Image_As_triggered()
98 {
99  QString path = *directory_;
100  path = path + "/" + name_;
101 
102  QString filename =
103  QFileDialog::getSaveFileName(this,
104  tr("Save File"),
105  path,
106  tr("Scalable Vector Graphics (*.svg);; "
107  "Enhanced Windows Metafile (*.emf);; "
108  "Portable Document Format (*.pdf);; "
109  "Tagged Image File Format (*.tif);; "
110  "Windows Bitmap (*.bmp);; "
111  "Portable Network Graphics (*.png);; "
112  "JPEG (*.jpg)"));
113  ui->mapPlot->SaveImage(filename);
114  raise();
115 }
116 
121 void MapViewer::on_actionShow_Axes_toggled(bool arg1)
122 {
123  workspace_->GetMap(map_keys_)->ShowAxes(arg1);
124  ui->mapPlot->replot(QCustomPlot::rpImmediate);
125 }
126 
131 void MapViewer::on_actionShow_Color_Scale_toggled(bool arg1)
132 {
133  workspace_->GetMap(map_keys_)->ShowColorScale(arg1);
134  ui->mapPlot->replot(QCustomPlot::rpImmediate);
135 }
136 
140 void MapViewer::on_actionSet_Color_Scheme_triggered()
141 {
142  if (!workspace_->GetMap(map_keys_)->global_gradient_key().isEmpty())
143  QMessageBox::warning(this, "Global Gradient",
144  "Changing the color gradient will detach this map"
145  "from the global gradient");
146  QStringList gradient_names = workspace_->GradientNames();
147  QString gradient_key = QInputDialog::getItem(this, "Select Gradient", "Gradient",
148  gradient_names);
149  QCPColorGradient new_gradient = workspace_->GetGradient(gradient_key);
150  workspace_->GetMap(map_keys_)->setGradient(new_gradient);
151 }
152 
156 void MapViewer::on_actionAdd_Scale_Bar_triggered()
157 {
158  //widget will delete itself
159  ScaleBarDialog *scale_bar_dialog = new ScaleBarDialog(this, workspace_->GetMap(map_keys_));
160  scale_bar_dialog->setAttribute(Qt::WA_DeleteOnClose);
161  scale_bar_dialog->show();
162 }
163 
164 
169 void MapViewer::on_actionLock_Size_toggled(bool arg1)
170 {
171  workspace_->GetMap(map_keys_)->LockMapDisplaySize(arg1);
172 }
173 
177 void MapViewer::on_actionReset_Size_triggered()
178 {
179  workspace_->GetMap(map_keys_)->ResetMapWidgetSize();
180 }
181 
186 void MapViewer::on_actionReproportion_triggered()
187 {
188  workspace_->GetMap(map_keys_)->RescaleMapWidget();
189 }
190 
191 void MapViewer::on_actionSet_Font_triggered()
192 {
193  bool ok;
194  QFont font = QFontDialog::getFont(&ok,
195  QFont("Arial", 12, QFont::Normal),
196  this, "Select Font");
197  if (ok) workspace_->GetMap(map_keys_)->SetFonts(font);
198 }
199 
200 void MapViewer::on_actionSet_Color_Scale_Label_triggered()
201 {
202  QString current_label = ui->mapPlot->ColorScaleLabel();
203  bool ok = true;
204  QString new_label = QInputDialog::getText(this, "Enter label",
205  "Label",
206  QLineEdit::Normal,
207  current_label, &ok);
208  if (ok) ui->mapPlot->SetColorScaleLabel(new_label);
209 }
210 
211 void MapViewer::on_actionSet_Global_Color_Scale_triggered()
212 {
213  QStringList global_scale_names = workspace_->GlobalGradientKeys();
214  if (!global_scale_names.size()){
215  QMessageBox::information(this, "No Global Gradients",
216  "No global gradients exist. To create a new"
217  "gradient, select Tools->Global Color Scales"
218  "in the main window");
219  return;
220  }
221  bool ok;
222  QString key = QInputDialog::getItem(this, "Select Global Gradient",
223  "Gradient", global_scale_names,
224  0, false, &ok);
225  if (ok)
226  workspace_->GetMap(map_keys_)->SetGlobalGradient(key);
227 }
228 
229 void MapViewer::keyPressEvent(QKeyEvent *event)
230 {
231  //arrow keys on some laptops might be difficult to use
232  //so why not also accept WASD and HJKL?
233 
234  switch (event->key()) {
235  case Qt::Key_Up:
236  case Qt::Key_W:
237  case Qt::Key_K:
238  ui->mapPlot->MoveHorizontalCrosshair(1);
239  return;
240  case Qt::Key_Down:
241  case Qt::Key_S:
242  case Qt::Key_J:
243  ui->mapPlot->MoveHorizontalCrosshair(-1);
244  return;
245  case Qt::Key_Left:
246  case Qt::Key_A:
247  case Qt::Key_H:
248  ui->mapPlot->MoveVerticalCrosshair(-1);
249  return;
250  case Qt::Key_Right:
251  case Qt::Key_D:
252  case Qt::Key_L:
253  ui->mapPlot->MoveVerticalCrosshair(1);
254  return;
255  case Qt::Key_Enter:
256  case Qt::Key_Return:
257  case Qt::Key_Space:
258  emit RequestHeldSpectrumPlot(map_keys_.first(),
259  map_keys_.last(),
260  ui->mapPlot->GetCrosshairPosition());
261  return;
262  default:
263  return;
264  }
265 }
266 
267 void MapViewer::showEvent(QShowEvent *event)
268 {
269  workspace_->main_window()->plot_viewer()->AddTab(name_);
270  workspace_->main_window()->SetPlotViewerActionChecked(true);
271  event->accept();
272 }
273 
274 
275 void MapViewer::on_actionCenter_Color_Scale_at_0_triggered()
276 {
277  ui->mapPlot->CenterAtZero();
278 }
void keyPressEvent(QKeyEvent *event)
Definition: mapviewer.cpp:229
Definition: ahcadialog.h:26
void showEvent(QShowEvent *event)
Definition: mapviewer.cpp:267
void RequestSpectrumPlot(QString dataset_key, QString map_name, size_t index)
void CoordinatesChanged(double x, double y, double z)
PlotViewer * plot_viewer()
Definition: mainwindow.cpp:890
void SetStatusbar(double x, double y, double z)
Definition: mapviewer.cpp:77
The MapPlot class A subclass of QCustomPlot for handling a specfic kind of color map. Provides a wrapper for a QCPColorScale and a QCPColorMap which are child widgets.
Definition: mapplot.h:33
void SpectrumRequested(QString dataset_key, QString map_name, size_t index)
Definition: mainwindow.cpp:993
void HeldSpectrumRequested(QString dataset_key, QString map_name, size_t index)
void SpectrumRequested(size_t index)
MapViewer::SpectrumRequested.
Definition: mapviewer.cpp:70
The MapViewer class Displays the image created by MapData.
Definition: mapviewer.h:45
void SpectrumRequested(size_t index)
void SetHoldCheckBoxChecked(bool checked)
Definition: plotviewer.cpp:115
The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot...
Definition: qcustomplot.h:1715
MapPlot * mapPlot()
Definition: mapviewer.cpp:55
Defines a color gradient for use with e.g. QCPColorMap.
Definition: qcustomplot.h:1905
MapViewer(MainWindow *parent, QStringList map_keys, QSharedPointer< VespucciWorkspace > ws)
MapViewer::MapViewer.
Definition: mapviewer.cpp:31
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58
void RequestHeldSpectrumPlot(QString dataset_key, QString map_name, size_t index)
The ScaleBarDialog class Dialog for the user to create a scale bar on the image.