Qt Virtual Chart Table (QVCT)
CDeviceOverlayActionsView.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QFileInfo>
21 #include <QHBoxLayout>
22 #include <QPushButton>
23 
24 // QVCT
25 #include "QVCTRuntime.hpp"
27 
28 
29 //------------------------------------------------------------------------------
30 // CONSTRUCTORS / DESTRUCTOR
31 //------------------------------------------------------------------------------
32 
34 {
36 }
37 
39 {
40  // Create the buttons
41  // ... order invert
42  pqPushButtonOrderInvert = new QPushButton( QIcon( ":icons/32x32/order_invert.png" ), "" );
43  pqPushButtonOrderInvert->setToolTip( tr("[overlay] Invert order") );
44  pqPushButtonOrderInvert->setMaximumSize( 36, 34 );
45  QWidget::connect( pqPushButtonOrderInvert, SIGNAL( clicked() ), this, SLOT( slotOrderInvert() ) );
46  // ... order ascending
47  pqPushButtonOrderAscending = new QPushButton( QIcon( ":icons/32x32/order_ascending.png" ), "" );
48  pqPushButtonOrderAscending->setToolTip( tr("[overlay] Sort in ascending order") );
49  pqPushButtonOrderAscending->setMaximumSize( 36, 34 );
50  QWidget::connect( pqPushButtonOrderAscending, SIGNAL( clicked() ), this, SLOT( slotOrderAscending() ) );
51  // ... order descending
52  pqPushButtonOrderDescending = new QPushButton( QIcon( ":icons/32x32/order_descending.png" ), "" );
53  pqPushButtonOrderDescending->setToolTip( tr("[overlay] Sort in descending order") );
54  pqPushButtonOrderDescending->setMaximumSize( 36, 34 );
55  QWidget::connect( pqPushButtonOrderDescending, SIGNAL( clicked() ), this, SLOT( slotOrderDescending() ) );
56  // ... save
57  pqPushButtonSave = new QPushButton( QIcon( ":icons/32x32/save_select.png" ), "" );
58  pqPushButtonSave->setToolTip( tr("Save selected devices to disk") );
59  pqPushButtonSave->setMaximumSize( 36, 34 );
60  QWidget::connect( pqPushButtonSave, SIGNAL( clicked() ), this, SLOT( slotSave() ) );
61  // ... delete
62  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete_select.png" ), "" );
63  pqPushButtonDelete->setToolTip( tr("Delete selected devices") );
64  pqPushButtonDelete->setMaximumSize( 36, 34 );
65  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
66 
67  // Add buttons
68  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
69  __pqHBoxLayoutButtons->addWidget( pqPushButtonOrderInvert, 0, Qt::AlignLeft );
70  __pqHBoxLayoutButtons->addWidget( pqPushButtonOrderAscending, 0, Qt::AlignLeft );
71  __pqHBoxLayoutButtons->addWidget( pqPushButtonOrderDescending, 0, Qt::AlignLeft );
72  __pqHBoxLayoutButtons->addWidget( pqPushButtonSave, 0, Qt::AlignLeft );
73  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignLeft );
74 
75  // Set the layout
76  QDialog::setLayout( __pqHBoxLayoutButtons );
77 
78 }
79 
80 
81 //------------------------------------------------------------------------------
82 // METHODS
83 //------------------------------------------------------------------------------
84 
85 //
86 // SLOTS
87 //
88 
90 {
91  do // error-catching block
92  {
93  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
94  QTreeWidgetItem* __pqTreeWidgetItem_current = __poDeviceOverlay->currentItem();
95  if( !__pqTreeWidgetItem_current ) break;
96  switch( __pqTreeWidgetItem_current->type() )
97  {
98 
100  {
101  int __iHead = 0, __iTail = __pqTreeWidgetItem_current->childCount()-1;
102  while( __iTail > __iHead )
103  {
104  QTreeWidgetItem* __pqTreeWidgetItem_head = __pqTreeWidgetItem_current->child( __iHead );
105  QTreeWidgetItem* __pqTreeWidgetItem_tail = __pqTreeWidgetItem_current->child( __iTail );
106  __pqTreeWidgetItem_current->removeChild( __pqTreeWidgetItem_head );
107  __pqTreeWidgetItem_current->removeChild( __pqTreeWidgetItem_tail );
108  __pqTreeWidgetItem_current->insertChild( __iHead++, __pqTreeWidgetItem_tail );
109  __pqTreeWidgetItem_current->insertChild( __iTail--, __pqTreeWidgetItem_head );
110  }
112  }
113  break;
114 
115  default:;
116 
117  }
118  }
119  while( false ); // error-catching block
120  QDialog::accept();
121 }
122 
124 {
125  do // error-catching block
126  {
127  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
128  QTreeWidgetItem* __pqTreeWidgetItem_current = __poDeviceOverlay->currentItem();
129  if( !__pqTreeWidgetItem_current ) break;
130  switch( __pqTreeWidgetItem_current->type() )
131  {
132 
134  __pqTreeWidgetItem_current->sortChildren( CDeviceOverlay::NAME, Qt::AscendingOrder );
136  break;
137 
138  default:;
139 
140  }
141  }
142  while( false ); // error-catching block
143  QDialog::accept();
144 }
145 
147 {
148  do // error-catching block
149  {
150  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
151  QTreeWidgetItem* __pqTreeWidgetItem_current = __poDeviceOverlay->currentItem();
152  if( !__pqTreeWidgetItem_current ) break;
153  switch( __pqTreeWidgetItem_current->type() )
154  {
155 
157  __pqTreeWidgetItem_current->sortChildren( CDeviceOverlay::NAME, Qt::DescendingOrder );
159  break;
160 
161  default:;
162 
163  }
164  }
165  while( false ); // error-catching block
166  QDialog::accept();
167 }
168 
170 {
171  do // error-catching block
172  {
173  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::SAVE, tr("Save Device"), tr("QVCT Files")+" (*.qvct)" );
174  if( __qsFilename.isEmpty() ) break;
175  QFileInfo __qFileInfo( __qsFilename );
176  if( __qFileInfo.suffix().isEmpty() ) __qsFilename += ".qvct";
177  QStringList __qsListExtensions; __qsListExtensions << "qvct";
178  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::SAVE, __qsFilename, &__qsListExtensions ) ) break;
179  QVCTRuntime::useDeviceOverlay()->save( __qsFilename, 0 ); // no device = save selection
180  }
181  while( false ); // error-catching block
182  QDialog::accept();
183 }
184 
186 {
187  do // error-catching block
188  {
189  if( !QVCTRuntime::useMainWindow()->deleteConfirm( tr("Selected device(s)") ) ) break;
190  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
191  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
192  __pqMutexDataChange->lock();
193  __poDeviceOverlay->deleteSelection();
194  __pqMutexDataChange->unlock();
196  }
197  while( false ); // error-catching block
198  QDialog::accept();
199 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
void slotDelete()
[UI:Slot] Slot to delete overlay's selected content
void slotOrderAscending()
[UI:Slot] Slot to order overlay's content in ascending direction
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonSave
[UI:Button] Load
QPushButton * pqPushButtonOrderInvert
[UI:Button] Order invert
void slotOrderInvert()
[UI:Slot] Slot to invert overlay's content order
void slotSave()
[UI:Slot] Slot to save overlay's selected content to file
QPushButton * pqPushButtonOrderAscending
[UI:Button] Order ascending
void slotOrderDescending()
[UI:Slot] Slot to order overlay's content in descending direction
QPushButton * pqPushButtonOrderDescending
[UI:Button] Order descending
QPushButton * pqPushButtonDelete
[UI:Button] Delete
[UI] Device overlay container
int deleteSelection()
Deletes selected devices from this overlay.
@ NAME
Device name.
void save(const QString &_rqsFilename, CDevice *_poDevice=0, bool _bApplicationDump=false) const
Save this object's content (device) to the given file (all selected items if no device is given)
QString fileDialog(QVCT::EFileOperation _eFileOperation, const QString &_rqsTitle, const QString &_rqsFilter)
Displays a generic dialog to pick a file for the given operation (open/save)
@ OVERLAY
(Base) overlay
static CDeviceOverlay * useDeviceOverlay()
static QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ SAVE
Definition: QVCT.hpp:42