2 #include <QSignalMapper> 4 #include <QInputDialog> 7 #include <QApplication> 12 #include "ui_tabbedplotwidget.h" 17 QMainWindow *main_window_,
20 QMainWindow *parent ) :
22 _mapped_data(mapped_data),
29 if( main_window == parent){
39 throw std::runtime_error(
"This is not supposed to happen");
48 tabWidget()->tabBar()->installEventFilter(
this );
54 iconSave.addFile(QStringLiteral(
":/icons/resources/light/save.png"), QSize(26, 26));
101 tabWidget()->addTab( tab, QString(
"plot") );
103 QApplication::processEvents();
117 QDomElement tabbed_area = doc.createElement(
"tabbed_widget" );
119 tabbed_area.setAttribute(
"name",
_name);
127 element.setAttribute(
"tab_name",
tabWidget()->tabText(
i) );
128 tabbed_area.appendChild( element );
131 QDomElement current_plotmatrix = doc.createElement(
"currentPlotMatrix" );
132 current_plotmatrix.setAttribute(
"index",
tabWidget()->currentIndex() );
133 tabbed_area.appendChild( current_plotmatrix );
143 QDomElement plotmatrix_el;
145 for ( plotmatrix_el = tabbed_area.firstChildElement(
"plotmatrix" ) ;
146 !plotmatrix_el.isNull();
147 plotmatrix_el = plotmatrix_el.nextSiblingElement(
"plotmatrix" ) )
150 if( index == num_tabs)
156 bool success = plot_matrix->
xmlLoadState( plotmatrix_el );
159 if( plotmatrix_el.hasAttribute(
"tab_name"))
161 QString tab_name = plotmatrix_el.attribute(
"tab_name" );
162 tabWidget()->setTabText( index, tab_name );
163 plot_matrix->
setName( tab_name );
175 while( num_tabs > index ){
180 QDomElement current_plotmatrix = tabbed_area.firstChildElement(
"currentPlotMatrix" );
181 int current_index = current_plotmatrix.attribute(
"index" ).toInt();
183 if(current_index>=0 && current_index <
tabWidget()->count())
185 tabWidget()->setCurrentIndex( current_index );
192 ui->buttonLinkHorizontalScale->setEnabled( !streaming_mode );
193 ui->pushVerticalResize->setEnabled( !streaming_mode );
194 ui->pushHorizontalResize->setEnabled( !streaming_mode );
205 int idx =
tabWidget()->tabBar()->currentIndex ();
208 QString newName = QInputDialog::getText (
209 this, tr (
"Change Name of the selected tab"),
210 tr (
"Insert New Tab Name"),
223 int idx =
tabWidget()->tabBar()->currentIndex();
226 QFileDialog saveDialog;
227 saveDialog.setAcceptMode(QFileDialog::AcceptSave);
228 saveDialog.setDefaultSuffix(
"png");
231 saveDialog.setNameFilter(
"Compatible formats (*.jpg *.jpeg *.png)");
235 if(saveDialog.result() == QDialog::Accepted && !saveDialog.selectedFiles().empty())
237 QString fileName = saveDialog.selectedFiles().first();
245 QPixmap pixmap (1200,900);
246 QPainter * painter =
new QPainter(&pixmap);
248 if ( !fileName.isEmpty() )
252 int delta_X = pixmap.width() / matrix->
colsCount();
253 int delta_Y = pixmap.height() / matrix->
rowsCount();
255 for (
unsigned c=0; c< matrix->
colsCount(); c++)
257 for (
unsigned r=0; r< matrix->
rowsCount(); r++)
260 QRect rect(delta_X*c, delta_Y*r, delta_X, delta_Y);
261 rend.
render(widget,painter, rect);
264 pixmap.save(fileName);
302 int src_row, src_col;
306 auto func = [&](QTabWidget * tabs)
308 for (
int t=0; t < tabs->count(); t++)
312 for(
unsigned row=0; row< matrix->
rowsCount(); row++)
314 for(
unsigned col=0; col< matrix->
colsCount(); col++)
317 if( plot->windowTitle() == plot_name)
332 func( it.second->tabWidget() );
339 src_matrix->
gridLayout()->removeWidget( source );
340 dst_matrix->
gridLayout()->removeWidget( destination );
342 src_matrix->
gridLayout()->addWidget( destination, src_row, src_col );
343 dst_matrix->
gridLayout()->addWidget( source, 0, 0 );
375 this->parent()->deleteLater();
390 bool close_confirmed =
true;
394 close_confirmed =
false;
398 QMessageBox::StandardButton do_remove = QMessageBox::Yes;
400 if( close_confirmed )
403 QApplication::processEvents();
405 do_remove = QMessageBox::question(
this, tr(
"Warning"),
406 tr(
"Do you really want to destroy this tab?\n"),
407 QMessageBox::Yes | QMessageBox::No,
410 if( do_remove == QMessageBox::Yes )
420 for(
unsigned p=0; p< matrix->
plotCount(); p++)
448 int index =
tabWidget()->tabBar()->currentIndex ();
450 const QString& tab_name = this->
tabWidget()->tabText(index);
452 destination_widget->
tabWidget()->addTab( tab_to_move, tab_name );
454 qDebug() <<
"move "<< tab_name<<
" into " << destination_name;
467 case LabelStatus::LEFT:
_labels_status = LabelStatus::HIDDEN;
break;
468 case LabelStatus::RIGHT:
_labels_status = LabelStatus::LEFT;
break;
469 case LabelStatus::HIDDEN:
_labels_status = LabelStatus::RIGHT;
break;
477 QTabBar* tab_bar =
tabWidget()->tabBar();
481 if( event->type() == QEvent::MouseButtonPress)
483 QMouseEvent *mouse_event =
static_cast<QMouseEvent*
>(event);
485 int index = tab_bar->tabAt( mouse_event->pos() );
486 tab_bar->setCurrentIndex( index );
489 if( mouse_event->button() == Qt::RightButton )
491 QMenu* submenu =
new QMenu(
"Move tab to...");
494 std::map<QString,TabbedPlotWidget*>::iterator it;
495 QSignalMapper* signalMapper =
new QSignalMapper(submenu);
498 QAction* action_new_window = submenu->addAction(
"New Window" );
501 icon.addFile(QStringLiteral(
":/icons/resources/light/stacks.png"), QSize(16, 16));
503 action_new_window->setIcon( icon);
504 submenu->addSeparator();
511 QString
name = it.first;
513 if( tabbed_menu !=
this )
515 QAction*
action = submenu->addAction( name );
516 connect(action, SIGNAL(triggered()), signalMapper, SLOT(map()));
517 signalMapper->setMapping( action, name );
524 _tab_menu->exec( mouse_event->globalPos() );
526 submenu->deleteLater();
532 return QObject::eventFilter(obj, event);
541 for(
unsigned p=0; p< matrix->
plotCount(); p++)
583 ui->widgetControls->setVisible(visible);
void maximumZoomOutVertical()
QGridLayout * gridLayout()
void onPlotMatrixAdded(PlotMatrix *matrix)
QDomElement xmlSaveState(QDomDocument &doc) const
bool xmlLoadState(QDomElement &plotmatrix_element)
PlotWidget * plotAt(unsigned row, unsigned column)
Renderer for exporting a plot to a document, a printer or anything else, that is supported by QPainte...
const QString & name() const
unsigned plotCount() const
unsigned colsCount() const
void on_tabbedAreaDestroyed(QObject *object)
unsigned rowsCount() const
void setHorizontalLink(bool linked)
virtual void render(QwtPlot *, QPainter *, const QRectF &rect) const
void setName(const QString &new_name)
void maximumZoomOutHorizontal()
void onCreateFloatingWindow(PlotMatrix *first_tab=nullptr)