Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkMultiWidgetLayoutSelectionWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
16  : QWidget(parent)
17 {
18  Init();
19 }
20 
21 void QmitkMultiWidgetLayoutSelectionWidget::Init()
22 {
23  ui.setupUi(this);
24 
25  auto stylesheet = "QTableWidget::item{background-color: white;}\nQTableWidget::item:selected{background-color: #1C97EA;}";
26  ui.tableWidget->setStyleSheet(stylesheet);
27 
28  connect(ui.tableWidget, &QTableWidget::itemSelectionChanged, this, &QmitkMultiWidgetLayoutSelectionWidget::OnTableItemSelectionChanged);
29  connect(ui.setLayoutPushButton, &QPushButton::clicked, this, &QmitkMultiWidgetLayoutSelectionWidget::OnSetLayoutButtonClicked);
30 }
31 
32 void QmitkMultiWidgetLayoutSelectionWidget::OnTableItemSelectionChanged()
33 {
34  QItemSelectionModel* selectionModel = ui.tableWidget->selectionModel();
35 
36  int row = 0;
37  int column = 0;
38  QModelIndexList indices = selectionModel->selectedIndexes();
39  if (indices.size() > 0)
40  {
41  row = indices[0].row();
42  column = indices[0].column();
43 
44  QModelIndex topLeft = ui.tableWidget->model()->index(0, 0, QModelIndex());
45  QModelIndex bottomRight = ui.tableWidget->model()->index(row, column, QModelIndex());
46 
47  QItemSelection cellSelection;
48  cellSelection.select(topLeft, bottomRight);
49  selectionModel->select(cellSelection, QItemSelectionModel::Select);
50  }
51 }
52 
53 void QmitkMultiWidgetLayoutSelectionWidget::OnSetLayoutButtonClicked()
54 {
55  int row = 0;
56  int column = 0;
57  QModelIndexList indices = ui.tableWidget->selectionModel()->selectedIndexes();
58  if (indices.size() > 0)
59  {
60  // find largest row and column
61  for (const QModelIndex modelIndex : indices)
62  {
63  if (modelIndex.row() > row)
64  {
65  row = modelIndex.row();
66  }
67  if (modelIndex.column() > column)
68  {
69  column = modelIndex.column();
70  }
71  }
72 
73  close();
74  emit LayoutSet(row+1, column+1);
75  }
76 }
void LayoutSet(int row, int column)