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

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • core
verificationdelegate.cpp
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright (C) 2009-2011 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "verificationdelegate.h"
21 #include "verifier.h"
22 #include "verificationmodel.h"
23 
24 #include <KComboBox>
25 #include <KLineEdit>
26 
27 struct VerificationDelegatePrivate
28 {
29  VerificationDelegatePrivate()
30  {
31  }
32 
33  ~VerificationDelegatePrivate()
34  {
35  }
36 
37  QStringList hashTypes;
38 };
39 
40 VerificationDelegate::VerificationDelegate(QObject *parent)
41  : QStyledItemDelegate(parent),
42  d(new VerificationDelegatePrivate)
43 {
44  d->hashTypes = Verifier::supportedVerficationTypes();
45  d->hashTypes.sort();
46 }
47 
48 QWidget *VerificationDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
49 {
50  Q_UNUSED(option)
51 
52  if (index.isValid()) {
53  if (index.column() == VerificationModel::Type) {
54  if (d->hashTypes.count()) {
55  KComboBox *hashTypes = new KComboBox(parent);
56  hashTypes->addItems(d->hashTypes);
57 
58  return hashTypes;
59  }
60  } else if (index.column() == VerificationModel::Checksum) {
61  return new KLineEdit(parent);
62  }
63  }
64 
65  return 0;
66 }
67 
68 void VerificationDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
69 {
70  if (index.isValid() && editor) {
71  if (index.column() == VerificationModel::Type) {
72  KComboBox *hashTypes = static_cast<KComboBox*>(editor);
73  const QString hashType = index.data().toString();
74  hashTypes->setCurrentItem(hashType);
75  } else if (index.column() == VerificationModel::Checksum) {
76  KLineEdit *line = static_cast<KLineEdit*>(editor);
77  const QString checksum = index.data().toString();
78  line->setText(checksum);
79  }
80  }
81 }
82 
83 void VerificationDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
84 {
85  if (index.isValid() && editor && model) {
86  if (index.column() == VerificationModel::Type) {
87  KComboBox *hashTypes = static_cast<KComboBox*>(editor);
88  model->setData(index, hashTypes->currentText());
89  } else if (index.column() == VerificationModel::Checksum) {
90  KLineEdit *line = static_cast<KLineEdit*>(editor);
91  model->setData(index, line->text());
92  }
93  }
94 }
95 
96 void VerificationDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
97 {
98  Q_UNUSED(index)
99  editor->setGeometry(option.rect);
100 }
101 
102 QSize VerificationDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
103 {
104  //make the sizeHint a little bit nicer to have more beautiful editors
105  QSize hint;
106  hint.setWidth(QStyledItemDelegate::sizeHint(option, index).width());
107  hint.setHeight(option.fontMetrics.height() + 7);
108  return hint;
109 }
VerificationDelegate::VerificationDelegate
VerificationDelegate(QObject *parent=0)
Definition: verificationdelegate.cpp:40
verificationmodel.h
VerificationDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: verificationdelegate.cpp:96
QWidget
Verifier::supportedVerficationTypes
static QStringList supportedVerficationTypes()
Returns the supported verification types.
Definition: verifier.cpp:216
QObject
QStyledItemDelegate
VerificationDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: verificationdelegate.cpp:48
VerificationDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: verificationdelegate.cpp:68
verifier.h
QAbstractItemModel
VerificationDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: verificationdelegate.cpp:102
verificationdelegate.h
VerificationDelegate::setModelData
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: verificationdelegate.cpp:83
VerificationModel::Type
Definition: verificationmodel.h:38
VerificationModel::Checksum
Definition: verificationmodel.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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