Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkTrackingSourcesCheckBoxPanelWidget.h"
00019
00020
00021
00022
00023 QmitkTrackingSourcesCheckBoxPanelWidget::QmitkTrackingSourcesCheckBoxPanelWidget(QWidget* parent)
00024 : QWidget(parent), m_Controls(NULL), m_SourceCheckboxes(NULL), m_NavigationDatas(NULL), m_SelectedIds(NULL)
00025 {
00026 this->CreateQtPartControl( this );
00027 m_SourceCheckboxes = new TrackingSourcesCheckboxes();
00028 }
00029
00030 QmitkTrackingSourcesCheckBoxPanelWidget::~QmitkTrackingSourcesCheckBoxPanelWidget()
00031 {
00032 delete m_SelectedIds;
00033 delete m_SourceCheckboxes;
00034 delete m_NavigationDatas;
00035 }
00036
00037 void QmitkTrackingSourcesCheckBoxPanelWidget::CreateQtPartControl(QWidget *parent)
00038 {
00039 if (!m_Controls)
00040 {
00041
00042 m_Controls = new Ui::QmitkTrackingSourcesCheckBoxPanelWidgetControls;
00043 m_Controls->setupUi(parent);
00044
00045 this->CreateConnections();
00046 }
00047 }
00048
00049 void QmitkTrackingSourcesCheckBoxPanelWidget::CreateConnections()
00050 {
00051 connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(toggled(bool)), this, SLOT(OnPerformActionClicked(bool)) ) ;
00052 connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(clicked()), this, SLOT(OnPerformActionClicked()) ) ;
00053 }
00054
00055
00056 void QmitkTrackingSourcesCheckBoxPanelWidget::SetNavigationDatas(std::vector<mitk::NavigationData::Pointer>* navDatas)
00057 {
00058 if( navDatas != NULL )
00059 m_NavigationDatas = navDatas;
00060 }
00061
00062
00063 void QmitkTrackingSourcesCheckBoxPanelWidget::AddNavigationData(mitk::NavigationData::Pointer nd)
00064 {
00065 if(m_NavigationDatas == NULL)
00066 m_NavigationDatas = new std::vector<mitk::NavigationData::Pointer>();
00067
00068 if( nd.IsNotNull() )
00069 m_NavigationDatas->push_back(nd);
00070 }
00071
00072
00073
00074 const std::vector<int>* QmitkTrackingSourcesCheckBoxPanelWidget::GetSelectedTrackingSourcesIDs()
00075 {
00076 if(m_SelectedIds == NULL)
00077 m_SelectedIds = new std::vector<int>();
00078 else
00079 m_SelectedIds->clear();
00080
00081 for (unsigned int i=0; i < m_SourceCheckboxes->size(); i++)
00082 {
00083 if(m_SourceCheckboxes->at(i)->isChecked())
00084 m_SelectedIds->push_back(i);
00085 }
00086
00087 return m_SelectedIds;
00088 }
00089
00090 void QmitkTrackingSourcesCheckBoxPanelWidget::ClearPanel()
00091 {
00092 while(m_Controls->m_GridLayout->count() > 0)
00093 {
00094 QWidget* actWidget = m_Controls->m_GridLayout->itemAt(0)->widget();
00095 m_Controls->m_GridLayout->removeWidget(actWidget);
00096 delete actWidget;
00097 }
00098
00099 if(m_SourceCheckboxes != NULL || m_NavigationDatas != NULL)
00100 {
00101 m_SourceCheckboxes->clear();
00102 m_NavigationDatas->clear();
00103 }
00104
00105
00106 }
00107
00108 void QmitkTrackingSourcesCheckBoxPanelWidget::ClearSelectedIDs()
00109 {
00110 if(m_SelectedIds != NULL && !m_SelectedIds->empty())
00111 m_SelectedIds->clear();
00112 }
00113
00114 void QmitkTrackingSourcesCheckBoxPanelWidget::ShowSourceCheckboxes()
00115 {
00116 if( m_SourceCheckboxes != NULL )
00117 m_SourceCheckboxes->clear();
00118
00119 if( m_NavigationDatas == NULL )
00120 return;
00121
00122 QCheckBox* checkBox;
00123
00124 int row = 0;
00125 int column;
00126
00127 for(unsigned int i=0; i < m_NavigationDatas->size(); i++)
00128 {
00129 column = i % 4;
00130 if( i>0 && i%4==0 )
00131 row++;
00132
00133 QString name(m_NavigationDatas->at(i).GetPointer()->GetName());
00134
00135 checkBox = new QCheckBox(name, this);
00136
00137 connect( checkBox, SIGNAL(toggled(bool)), this , SLOT(OnCheckboxClicked(bool)) );
00138
00139 m_SourceCheckboxes->push_back(checkBox);
00140 m_Controls->m_GridLayout->addWidget(checkBox,row,column);
00141
00142 }
00143
00144 }
00145
00146 void QmitkTrackingSourcesCheckBoxPanelWidget::EnableCheckboxes(bool enable)
00147 {
00148 for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
00149 {
00150 m_SourceCheckboxes->at(i)->setEnabled(enable);
00151 }
00152 }
00153
00154 void QmitkTrackingSourcesCheckBoxPanelWidget::SelectAll()
00155 {
00156 for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
00157 {
00158 m_SourceCheckboxes->at(i)->setChecked(true);
00159 }
00160 }
00161
00162 void QmitkTrackingSourcesCheckBoxPanelWidget::DeselectAll()
00163 {
00164 for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
00165 {
00166 m_SourceCheckboxes->at(i)->setChecked(false);
00167 }
00168 }
00169
00170 void QmitkTrackingSourcesCheckBoxPanelWidget::SelectCheckbox(unsigned int idx)
00171 {
00172 m_SourceCheckboxes->at(idx)->setChecked(true);
00173 }
00174
00175 void QmitkTrackingSourcesCheckBoxPanelWidget::DeselectCheckbox(unsigned int idx)
00176 {
00177 m_SourceCheckboxes->at(idx)->setChecked(false);
00178 }
00179
00180
00181 void QmitkTrackingSourcesCheckBoxPanelWidget::OnCheckboxClicked(bool checked)
00182 {
00183 QCheckBox* sender = qobject_cast< QCheckBox* > (QObject::sender());
00184
00185 if( sender == NULL )
00186 throw std::invalid_argument("No sender found!");
00187
00188 int idx = -1;
00189
00190 for(unsigned int i=0 ;i < m_SourceCheckboxes->size(); i++)
00191 {
00192 if(sender == m_SourceCheckboxes->at(i))
00193 { idx=i;
00194 break;
00195 }
00196 }
00197
00198 if(idx>-1)
00199 {
00200 if(checked)
00201 emit Selected(idx);
00202 else
00203 emit Deselected(idx);
00204 }
00205
00206 }
00207
00208 void QmitkTrackingSourcesCheckBoxPanelWidget::SetInfoText(QString text)
00209 {
00210 m_Controls->m_InfoLabel->setText(text);
00211 }
00212
00213 void QmitkTrackingSourcesCheckBoxPanelWidget::SetActionPerformButtonText(QString text)
00214 {
00215 m_Controls->m_ActionButton->setText(text);
00216 }
00217
00218
00219 void QmitkTrackingSourcesCheckBoxPanelWidget::HideActionPerformButton(bool hide)
00220 {
00221 if(hide)
00222 m_Controls->m_ActionButton->hide();
00223 else
00224 m_Controls->m_ActionButton->show();
00225 }
00226
00227
00228 void QmitkTrackingSourcesCheckBoxPanelWidget::SetActionPerformButtonCheckable(bool checkable)
00229 {
00230 if(checkable)
00231 m_Controls->m_ActionButton->setCheckable(true);
00232 else
00233 m_Controls->m_ActionButton->setCheckable(false);
00234 }
00235
00236 void QmitkTrackingSourcesCheckBoxPanelWidget::OnPerformActionClicked(bool toggled)
00237 {
00238 if(toggled)
00239 emit PerformAction();
00240 else
00241 emit StopAction();
00242 }
00243
00244 void QmitkTrackingSourcesCheckBoxPanelWidget::OnPerformActionClicked()
00245 {
00246 emit Action();
00247 }