CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxInfoWidget.h"
34 
35 #include <QGridLayout>
36 #include <QVBoxLayout>
37 #include <QTableWidget>
38 #include "cxImage.h"
39 #include "cxTypeConversions.h"
40 
41 namespace cx {
42 
43 InfoWidget::InfoWidget(QWidget* parent, QString objectName, QString windowTitle) :
44  BaseWidget(parent, objectName, windowTitle)
45 {
46  toptopLayout = new QVBoxLayout(this);
47  toptopLayout->setMargin(0);
48  gridLayout = new QGridLayout;
49  gridLayout->setMargin(0);
50  toptopLayout->addLayout(gridLayout);
51 
52  mTableWidget = new QTableWidget(this);
53  mTableWidget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
54 }
55 
57 {
58  toptopLayout->addStretch();
59 }
60 
61 void InfoWidget::populateTableWidget(std::map<std::string, std::string>& info)
62 {
63  mTableWidget->setRowCount(info.size());
64  mTableWidget->setColumnCount(2);
65  QStringList horizontalHeaders;
66  horizontalHeaders << "Description";
67  horizontalHeaders << "Value";
68  mTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
69  mTableWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignLeft);
70  mTableWidget->horizontalHeaderItem(1)->setTextAlignment(Qt::AlignLeft);
71  mTableWidget->setColumnWidth(0, 200);
72  mTableWidget->setColumnWidth(1, 600);
73 
74  QFont boldFont;
75  boldFont.setBold(true);
76 
77  int row = 0;
78  std::map<std::string, std::string>::iterator it;
79  for(it = info.begin(); it != info.end(); ++it)
80  {
81  QTableWidgetItem *descriptionItem = new QTableWidgetItem(qstring_cast(it->first));
82  descriptionItem->setFont(boldFont);
83  descriptionItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
84  mTableWidget->setItem(row, 0, descriptionItem);
85 
86  QTableWidgetItem *valueItem = new QTableWidgetItem(qstring_cast(it->second));
87  valueItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
88  mTableWidget->setItem(row, 1, valueItem);
89 
90  row++;
91  }
92 }
93 
94 } /* namespace cx */
QString qstring_cast(const T &val)
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:69
void populateTableWidget(std::map< std::string, std::string > &info)
InfoWidget(QWidget *parent, QString objectName, QString windowTitle)
QGridLayout * gridLayout
Definition: cxInfoWidget.h:68
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108