NorMIT-nav  22.09
An IGT application
cxInfoWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxInfoWidget.h"
13 
14 #include <QGridLayout>
15 #include <QVBoxLayout>
16 #include <QTableWidget>
17 #include "cxImage.h"
18 #include "cxTypeConversions.h"
19 
20 namespace cx {
21 
22 InfoWidget::InfoWidget(QWidget* parent, QString objectName, QString windowTitle) :
23  BaseWidget(parent, objectName, windowTitle)
24 {
25  toptopLayout = new QVBoxLayout(this);
26  toptopLayout->setMargin(0);
27  gridLayout = new QGridLayout;
28  gridLayout->setMargin(0);
29  toptopLayout->addLayout(gridLayout);
30 
31  mTableWidget = new QTableWidget(this);
32  mTableWidget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
33 }
34 
36 {
37  toptopLayout->addStretch();
38 }
39 
40 void InfoWidget::populateTableWidget(std::map<std::string, std::string>& info)
41 {
42  mTableWidget->setRowCount(info.size());
43  mTableWidget->setColumnCount(2);
44  QStringList horizontalHeaders;
45  horizontalHeaders << "Description";
46  horizontalHeaders << "Value";
47  mTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
48  mTableWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignLeft);
49  mTableWidget->horizontalHeaderItem(1)->setTextAlignment(Qt::AlignLeft);
50  mTableWidget->setColumnWidth(0, 200);
51  mTableWidget->setColumnWidth(1, 600);
52 
53  QFont boldFont;
54  boldFont.setBold(true);
55 
56  int row = 0;
57  std::map<std::string, std::string>::iterator it;
58  for(it = info.begin(); it != info.end(); ++it)
59  {
60  QTableWidgetItem *descriptionItem = new QTableWidgetItem(qstring_cast(it->first));
61  descriptionItem->setFont(boldFont);
62  descriptionItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
63  mTableWidget->setItem(row, 0, descriptionItem);
64 
65  QTableWidgetItem *valueItem = new QTableWidgetItem(qstring_cast(it->second));
66  valueItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
67  mTableWidget->setItem(row, 1, valueItem);
68 
69  row++;
70  }
71 }
72 
73 } /* namespace cx */
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::InfoWidget::mTableWidget
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:48
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::InfoWidget::populateTableWidget
void populateTableWidget(std::map< std::string, std::string > &info)
Definition: cxInfoWidget.cpp:40
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cxImage.h
cxTypeConversions.h
cx::InfoWidget::gridLayout
QGridLayout * gridLayout
Definition: cxInfoWidget.h:47
cxInfoWidget.h
cx::InfoWidget::addStretch
void addStretch()
Definition: cxInfoWidget.cpp:35
cx::InfoWidget::InfoWidget
InfoWidget(QWidget *parent, QString objectName, QString windowTitle)
Definition: cxInfoWidget.cpp:22