• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • info
infoview.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "infoview.h"
24 
25 // tool
26 #include "infotool.h"
27 #include "statistictablemodel.h"
28 #include "infoviewsettings.h"
29 // KDE
30 #include <KPushButton>
31 #include <KGuiItem>
32 #include <KLocale>
33 #include <KGlobal>
34 #include <KApplication>
35 #include <KGlobalSettings>
36 // Qt
37 #include <QtGui/QSortFilterProxyModel>
38 #include <QtGui/QLabel>
39 #include <QtGui/QLayout>
40 #include <QtGui/QHeaderView>
41 #include <QtGui/QTreeView>
42 #include <QtGui/QFontMetrics>
43 
44 
45 namespace Kasten2
46 {
47 
48 InfoView::InfoView( InfoTool *tool, QWidget* parent )
49  : QWidget( parent ), mTool( tool )
50 {
51  QVBoxLayout *baseLayout = new QVBoxLayout( this );
52  baseLayout->setMargin( 0 );
53 
54  QHBoxLayout* topLineLayout = new QHBoxLayout();
55 
56  QLabel *label = new QLabel( i18nc("@label size of selected bytes","Size:"), this );
57  topLineLayout->addWidget( label );
58 
59  mSizeLabel = new QLabel( this );
60  const QString sizeToolTip =
61  i18nc( "@info:tooltip",
62  "The number of the bytes the statistic was built for." );
63  label->setToolTip( sizeToolTip );
64  mSizeLabel->setToolTip( sizeToolTip );
65  topLineLayout->addWidget( mSizeLabel, 10 );
66  connect( mTool->statisticTableModel(), SIGNAL(sizeChanged(int)),
67  SLOT(setByteArraySize(int)) );
68 
69  topLineLayout->addStretch();
70 
71  const KGuiItem updateGuiItem =
72  KGuiItem(i18nc("@action:button build the statistic of the byte frequency",
73  "&Build"),
74  QLatin1String("run-build"),
75  i18nc("@info:tooltip",
76  "Builds the byte frequency statistic for the bytes in the selected range."),
77  i18nc("@info:whatsthis",
78  "If you press the <interface>Build</interface> button,"
79  " the byte frequency statistic is built for the bytes in the selected range.") );
80  mUpdateButton = new KPushButton( updateGuiItem, this );
81  mUpdateButton->setEnabled( mTool->isApplyable() );
82  connect( mTool, SIGNAL(isApplyableChanged(bool)), mUpdateButton, SLOT(setEnabled(bool)) );
83  connect( mUpdateButton, SIGNAL(clicked(bool)), mTool, SLOT(updateStatistic()) );
84  topLineLayout->addWidget( mUpdateButton );
85 
86  baseLayout->addLayout( topLineLayout );
87 
88  mStatisticTableView = new QTreeView( this );
89  connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
90  SLOT(setFixedFontByGlobalSettings()) );
91  connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
92  SLOT(resizeColumnsWidth()) );
93  connect( KGlobalSettings::self(), SIGNAL(kdisplayStyleChanged()),
94  SLOT(resizeColumnsWidth()) );
95  setFixedFontByGlobalSettings(); //do this before setting model
96  mStatisticTableView->setObjectName( QLatin1String( "StatisticTable" ) );
97  mStatisticTableView->setRootIsDecorated( false );
98  mStatisticTableView->setItemsExpandable( false );
99  mStatisticTableView->setUniformRowHeights( true );
100  mStatisticTableView->setAllColumnsShowFocus( true );
101  mStatisticTableView->setSortingEnabled( true );
102  QHeaderView* header = mStatisticTableView->header();
103  header->setFont( font() );
104  header->setResizeMode( QHeaderView::Interactive );
105  header->setStretchLastSection( false );
106  // TODO: write subclass to filter count and percent by num, not string
107  QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel( this );
108  proxyModel->setDynamicSortFilter( true );
109  proxyModel->setSourceModel( mTool->statisticTableModel() );
110  mStatisticTableView->setModel( proxyModel );
111  mStatisticTableView->sortByColumn( StatisticTableModel::CountId, Qt::DescendingOrder );
112  connect( mTool->statisticTableModel(), SIGNAL(headerChanged()), SLOT(updateHeader()) );
113 
114  baseLayout->addWidget( mStatisticTableView, 10 );
115 
116  setByteArraySize( mTool->size() );
117 
118  //if nothing has changed reuse the old values. This means the info view is fully constructed much quicker.
119  const QList<int> columnsWidth = InfoViewSettings::columnsWidth();
120  const QString styleName = KApplication::style()->objectName();
121  const QString fixedFontData = KGlobalSettings::fixedFont().toString();
122  if ( columnsWidth.size() < StatisticTableModel::NoOfIds || styleName != InfoViewSettings::style()
123  || fixedFontData != InfoViewSettings::fixedFont() )
124  {
125  resizeColumnsWidth();
126  }
127  else
128  {
129  for (int i = 0; i < StatisticTableModel::NoOfIds; ++i)
130  {
131  header->resizeSection( i, columnsWidth.at( i ) );
132  }
133  }
134 }
135 
136 void InfoView::updateHeader()
137 {
138  mStatisticTableView->resizeColumnToContents( StatisticTableModel::ValueId );
139  mStatisticTableView->header()->headerDataChanged( Qt::Horizontal,
140  StatisticTableModel::ValueId, StatisticTableModel::ValueId );
141 }
142 
143 void InfoView::resizeColumnsWidth()
144 {
145  //kDebug() << "recalculating header width";
146  for (int i = 0; i < StatisticTableModel::NoOfIds; ++i)
147  {
148  mStatisticTableView->resizeColumnToContents( i );
149  }
150 }
151 
152 void InfoView::setByteArraySize( int size )
153 {
154  const QString sizeText = ( size < 1 ) ? // -1 is default, 0 should not happen
155  QString::fromLatin1( "-" ) :
156  i18np( "1 byte", "%1 bytes", size );
157 
158  mSizeLabel->setText( sizeText );
159 }
160 
161 void InfoView::setFixedFontByGlobalSettings()
162 {
163  mStatisticTableView->setFont( KGlobalSettings::fixedFont() );
164 }
165 
166 InfoView::~InfoView()
167 {
168  QList<int> columnsWidth;
169  const QHeaderView* header = mStatisticTableView->header();
170  for (int i = 0 ; i < StatisticTableModel::NoOfIds; ++i)
171  {
172  columnsWidth.append( header->sectionSize( i ) );
173  }
174  InfoViewSettings::setColumnsWidth( columnsWidth );
175  InfoViewSettings::setStyle( KApplication::style()->objectName() );
176  InfoViewSettings::setFixedFont( KGlobalSettings::fixedFont().toString() );
177  InfoViewSettings::self()->writeConfig();
178 }
179 
180 }
Kasten2::InfoView::~InfoView
virtual ~InfoView()
Definition: infoview.cpp:166
Kasten2::InfoViewSettings::style
static QString style()
Get Style.
Definition: infoviewsettings.h:51
QWidget
infotool.h
Kasten2::InfoView::setByteArraySize
void setByteArraySize(int size)
Definition: infoview.cpp:152
Kasten2::InfoViewSettings::self
static InfoViewSettings * self()
Definition: infoviewsettings.cpp:25
Kasten2::InfoTool::size
int size() const
Definition: infotool.cpp:52
Kasten2::InfoViewSettings::setColumnsWidth
static void setColumnsWidth(const QList< int > &v)
Set ColumnsWidth.
Definition: infoviewsettings.h:22
Kasten2::StatisticTableModel::CountId
Definition: statistictablemodel.h:49
Kasten2::InfoViewSettings::fixedFont
static QString fixedFont()
Get FixedFont.
Definition: infoviewsettings.h:70
Kasten2::InfoView::InfoView
InfoView(InfoTool *tool, QWidget *parent=0)
Definition: infoview.cpp:48
infoview.h
Kasten2::InfoViewSettings::columnsWidth
static QList< int > columnsWidth()
Get ColumnsWidth.
Definition: infoviewsettings.h:32
Kasten2::InfoViewSettings::setStyle
static void setStyle(const QString &v)
Set Style.
Definition: infoviewsettings.h:41
Kasten2::InfoViewSettings::setFixedFont
static void setFixedFont(const QString &v)
Set FixedFont.
Definition: infoviewsettings.h:60
statistictablemodel.h
Kasten2::InfoTool::isApplyable
bool isApplyable() const
Definition: infotool.cpp:53
Kasten2::InfoTool
Definition: infotool.h:48
ScriptValueConverter::toString
StringDataInformation * toString(const QScriptValue &value, const ParserInfo &info)
infoviewsettings.h
Kasten2::InfoTool::statisticTableModel
StatisticTableModel * statisticTableModel() const
Definition: infotool.cpp:51
Kasten2::StatisticTableModel::ValueId
Definition: statistictablemodel.h:47
Kasten2::InfoView::updateHeader
void updateHeader()
Definition: infoview.cpp:136
Kasten2::StatisticTableModel::NoOfIds
Definition: statistictablemodel.h:51
QList< int >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal