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

messagelist

  • sources
  • kde-4.12
  • kdepim
  • messagelist
  • utils
comboboxutils.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *******************************************************************************/
20 
21 #include "utils/comboboxutils.h"
22 
23 #include <QVariant>
24 
25 #include <KComboBox>
26 
27 using namespace MessageList::Utils;
28 
29 void ComboBoxUtils::fillIntegerOptionCombo( KComboBox *combo, const QList< QPair< QString, int > > &optionDescriptors )
30 {
31  int val = getIntegerOptionComboValue( combo, -1 );
32  combo->clear();
33  int valIdx = -1;
34  int idx = 0;
35 
36  QList< QPair< QString, int > >::ConstIterator end( optionDescriptors.end() );
37 
38  for( QList< QPair< QString, int > >::ConstIterator it = optionDescriptors.constBegin(); it != end; ++it )
39  {
40  if ( val == (*it).second )
41  valIdx = idx;
42  combo->addItem( (*it).first, QVariant( (*it).second ) );
43  ++idx;
44  }
45  if ( idx == 0)
46  {
47  combo->addItem( QLatin1String("-"), QVariant( (int)0 ) ); // always default to 0
48  combo->setEnabled( false );
49  } else {
50  if ( !combo->isEnabled() )
51  combo->setEnabled( true );
52  if ( valIdx >= 0 )
53  combo->setCurrentIndex( valIdx );
54  if ( combo->count() == 1 )
55  combo->setEnabled( false ); // disable when there is no choice
56  }
57 }
58 
59 void ComboBoxUtils::setIntegerOptionComboValue( KComboBox *combo, int value )
60 {
61  if(combo->itemData(combo->currentIndex()).toInt() == value) {
62  return;
63  }
64  int index = combo->findData(value);
65  if(index!=-1)
66  combo->setCurrentIndex( index );
67  else
68  combo->setCurrentIndex( 0 ); // default
69 }
70 
71 int ComboBoxUtils::getIntegerOptionComboValue( KComboBox *combo, int defaultValue )
72 {
73  const int idx = combo->currentIndex();
74  if ( idx < 0 )
75  return defaultValue;
76 
77  QVariant data = combo->itemData( idx );
78  bool ok;
79  const int val = data.toInt( &ok );
80  if ( !ok )
81  return defaultValue;
82  return val;
83 }
84 
MessageList::Utils::ComboBoxUtils::setIntegerOptionComboValue
void setIntegerOptionComboValue(KComboBox *combo, int value)
Sets the currently selected option in the specified combo.
Definition: comboboxutils.cpp:59
MessageList::Utils::ComboBoxUtils::fillIntegerOptionCombo
void fillIntegerOptionCombo(KComboBox *combo, const QList< QPair< QString, int > > &optionDescriptors)
Fills the specified KComboBox with the options available in optionDescriptors.
Definition: comboboxutils.cpp:29
comboboxutils.h
KComboBox
MessageList::Utils::ComboBoxUtils::getIntegerOptionComboValue
int getIntegerOptionComboValue(KComboBox *combo, int defaultValue)
Returns the identifier of the currently selected option in the specified combo.
Definition: comboboxutils.cpp:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messagelist

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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