[Uml-devel] KDE/kdesdk/umbrello/umbrello/dialogs
Andi Fischer
andi.fischer at hispeed.ch
Sat Aug 2 11:17:56 UTC 2008
SVN commit 840970 by fischer:
Sorting the types combobox for better finding the desired type, q3support--.
M +78 -78 umlattributedialog.cpp
M +21 -21 umlattributedialog.h
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/umlattributedialog.cpp #840969:840970
@@ -1,5 +1,4 @@
/***************************************************************************
- * *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
@@ -12,16 +11,15 @@
// own header
#include "umlattributedialog.h"
-// qt includes
-#include <q3groupbox.h>
-#include <q3buttongroup.h>
-#include <QLayout>
-#include <QCheckBox>
-#include <QRadioButton>
-#include <QLabel>
-#include <QVBoxLayout>
-#include <QHBoxLayout>
-#include <QGridLayout>
+// app includes
+#include "attribute.h"
+#include "classifier.h"
+#include "template.h"
+#include "umldoc.h"
+#include "uml.h"
+#include "dialog_utils.h"
+#include "object_factory.h"
+#include "import_utils.h"
// kde includes
#include <klineedit.h>
@@ -31,15 +29,15 @@
#include <kmessagebox.h>
#include <kdebug.h>
-// app includes
-#include "../attribute.h"
-#include "../classifier.h"
-#include "../template.h"
-#include "../umldoc.h"
-#include "../uml.h"
-#include "../dialog_utils.h"
-#include "../object_factory.h"
-#include "../codeimport/import_utils.h"
+// qt includes
+#include <QtGui/QGroupBox>
+#include <QtGui/QLayout>
+#include <QtGui/QCheckBox>
+#include <QtGui/QRadioButton>
+#include <QtGui/QLabel>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QGridLayout>
UMLAttributeDialog::UMLAttributeDialog( QWidget * pParent, UMLAttribute * pAttribute )
: KDialog( pParent)
@@ -59,23 +57,22 @@
void UMLAttributeDialog::setupDialog()
{
- UMLDoc * pDoc = UMLApp::app()->getDocument();
int margin = fontMetrics().height();
QFrame * frame = new QFrame( this );
setMainWidget( frame );
QVBoxLayout * mainLayout = new QVBoxLayout( frame );
- m_pValuesGB = new Q3GroupBox(i18n("General Properties"), frame );
+ m_pValuesGB = new QGroupBox(i18n("General Properties"), frame );
QGridLayout * valuesLayout = new QGridLayout(m_pValuesGB);
- valuesLayout -> setMargin(margin);
- valuesLayout -> setSpacing(10);
+ valuesLayout->setMargin(margin);
+ valuesLayout->setSpacing(10);
m_pTypeL = new QLabel(i18n("&Type:"), m_pValuesGB);
- valuesLayout -> addWidget(m_pTypeL, 0, 0);
+ valuesLayout->addWidget(m_pTypeL, 0, 0);
m_pTypeCB = new KComboBox(true, m_pValuesGB);
- valuesLayout -> addWidget(m_pTypeCB, 0, 1);
+ valuesLayout->addWidget(m_pTypeCB, 0, 1);
m_pTypeL->setBuddy(m_pTypeCB);
Dialog_Utils::makeLabeledEditField( m_pValuesGB, valuesLayout, 1,
@@ -91,65 +88,52 @@
m_pStereoTypeLE, m_pAttribute->getStereotype() );
m_pStaticCB = new QCheckBox( i18n("Classifier &scope (\"static\")"), m_pValuesGB );
- m_pStaticCB -> setChecked( m_pAttribute -> getStatic() );
- valuesLayout -> addWidget(m_pStaticCB, 4, 0);
+ m_pStaticCB->setChecked( m_pAttribute->getStatic() );
+ valuesLayout->addWidget(m_pStaticCB, 4, 0);
- mainLayout -> addWidget(m_pValuesGB);
+ mainLayout->addWidget(m_pValuesGB);
- m_pScopeBG = new Q3ButtonGroup(i18n("Visibility"), frame );
- QHBoxLayout * scopeLayout = new QHBoxLayout(m_pScopeBG);
- scopeLayout -> setMargin(margin);
+ m_pScopeGB = new QGroupBox(i18n("Visibility"), frame );
+ QHBoxLayout * scopeLayout = new QHBoxLayout(m_pScopeGB);
+ scopeLayout->setMargin(margin);
- m_pPublicRB = new QRadioButton(i18nc("access control public", "&Public"), m_pScopeBG);
- scopeLayout -> addWidget(m_pPublicRB);
+ m_pPublicRB = new QRadioButton(i18nc("access control public", "&Public"), m_pScopeGB);
+ scopeLayout->addWidget(m_pPublicRB);
- m_pPrivateRB = new QRadioButton(i18nc("access control private", "P&rivate"), m_pScopeBG);
- scopeLayout -> addWidget(m_pPrivateRB);
+ m_pPrivateRB = new QRadioButton(i18nc("access control private", "P&rivate"), m_pScopeGB);
+ scopeLayout->addWidget(m_pPrivateRB);
- m_pProtectedRB = new QRadioButton(i18nc("access control protected", "Prot&ected"), m_pScopeBG);
- scopeLayout -> addWidget(m_pProtectedRB);
+ m_pProtectedRB = new QRadioButton(i18nc("access control protected", "Prot&ected"), m_pScopeGB);
+ scopeLayout->addWidget(m_pProtectedRB);
- m_pImplementationRB = new QRadioButton(i18n("I&mplementation"), m_pScopeBG);
- scopeLayout -> addWidget(m_pImplementationRB);
+ m_pImplementationRB = new QRadioButton(i18n("I&mplementation"), m_pScopeGB);
+ scopeLayout->addWidget(m_pImplementationRB);
- mainLayout -> addWidget(m_pScopeBG);
- Uml::Visibility scope = m_pAttribute -> getVisibility();
- if( scope == Uml::Visibility::Public )
- m_pPublicRB -> setChecked( true );
- else if( scope == Uml::Visibility::Private )
- m_pPrivateRB -> setChecked( true );
- else if( scope == Uml::Visibility::Protected )
- m_pProtectedRB -> setChecked( true );
- else if( scope == Uml::Visibility::Implementation )
- m_pImplementationRB -> setChecked( true );
+ mainLayout->addWidget(m_pScopeGB);
- m_pTypeCB->setDuplicatesEnabled(false);//only allow one of each type in box
+ switch (m_pAttribute->getVisibility()) {
+ case Uml::Visibility::Public:
+ m_pPublicRB->setChecked( true );
+ break;
+ case Uml::Visibility::Private:
+ m_pPrivateRB->setChecked( true );
+ break;
+ case Uml::Visibility::Protected:
+ m_pProtectedRB->setChecked( true );
+ break;
+ case Uml::Visibility::Implementation:
+ m_pImplementationRB->setChecked( true );
+ break;
+ default:
+ break;
+ }
+
+ m_pTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
m_pTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
//now add the Concepts
- UMLClassifierList namesList( pDoc->getConcepts() );
- foreach (UMLClassifier* obj, namesList ) {
- insertType( obj->getFullyQualifiedName() );
- }
+ insertTypesSorted(m_pAttribute->getTypeName());
- //work out which one to select
- int typeBoxCount = 0;
- bool foundType = false;
- while (typeBoxCount < m_pTypeCB->count() && foundType == false) {
- QString typeBoxString = m_pTypeCB->itemText(typeBoxCount);
- if ( typeBoxString == m_pAttribute->getTypeName() ) {
- foundType = true;
- m_pTypeCB->setCurrentIndex(typeBoxCount);
- } else {
- typeBoxCount++;
- }
- }
-
- if (!foundType) {
- insertType( m_pAttribute->getTypeName(), 0 );
- m_pTypeCB->setCurrentIndex(0);
- }
-
m_pNameLE->setFocus();
connect( m_pNameLE, SIGNAL( textChanged ( const QString & ) ), SLOT( slotNameChanged( const QString & ) ) );
slotNameChanged(m_pNameLE->text() );
@@ -225,7 +209,7 @@
return false;
classifier = static_cast<UMLClassifier*>(obj);
}
- m_pAttribute->setType( classifier );
+ m_pAttribute->setType(classifier);
return true;
}
@@ -241,11 +225,27 @@
}
}
-void UMLAttributeDialog::insertType( const QString& type, int index )
+void UMLAttributeDialog::insertTypesSorted( const QString& type )
{
- m_pTypeCB->insertItem( index, type );
- m_pTypeCB->completionObject()->addItem( type );
+ UMLDoc * uDoc = UMLApp::app()->getDocument();
+ UMLClassifierList namesList( uDoc->getConcepts() );
+ QStringList types;
+ foreach (UMLClassifier* obj, namesList) {
+ types << obj->getFullyQualifiedName();
+ }
+ if ( !types.contains(type) ) {
+ types << type;
+ }
+ types.sort();
+
+ m_pTypeCB->clear();
+ m_pTypeCB->insertItems(-1, types);
+
+ int currentIndex = m_pTypeCB->findText(type);
+ if (currentIndex > -1) {
+ m_pTypeCB->setCurrentIndex(currentIndex);
+ }
+ m_pTypeCB->completionObject()->addItem(type);
}
-
#include "umlattributedialog.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/umlattributedialog.h #840969:840970
@@ -1,11 +1,10 @@
/***************************************************************************
- * *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2002-2006 *
+ * copyright (C) 2002-2008 *
* Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
@@ -13,23 +12,21 @@
#define UMLATTRIBUTEDIALOG_H
#include <kdialog.h>
-//Added by qt3to4:
-#include <QLabel>
-/**
- * @author Paul Hensgen
- * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
- */
-
-class Q3ButtonGroup;
class QCheckBox;
-class Q3GroupBox;
+class QGroupBox;
class QRadioButton;
+class QLabel;
class UMLAttribute;
class KComboBox;
class KLineEdit;
-class UMLAttributeDialog : public KDialog {
+/**
+ * @author Paul Hensgen
+ * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
+ */
+class UMLAttributeDialog : public KDialog
+{
Q_OBJECT
public:
UMLAttributeDialog( QWidget * pParent, UMLAttribute * pAttribute );
@@ -37,8 +34,8 @@
protected:
/**
- * Sets up the dialog
- */
+ * Sets up the dialog
+ */
void setupDialog();
/**
@@ -48,18 +45,21 @@
bool apply();
/**
- * Inserts @p type into the type-combobox as well as its completion object.
- */
- void insertType( const QString& type, int index = -1 );
+ * Inserts @p type into the type-combobox as well as its completion object.
+ * The combobox is cleared and all types together with the optional new one
+ * sorted and then added again.
+ * @param type a new type to add
+ */
+ void insertTypesSorted( const QString& type = "" );
/**
- * The Attribute to represent
- */
+ * The Attribute to represent
+ */
UMLAttribute * m_pAttribute;
//GUI Widgets
- Q3GroupBox * m_pAttsGB, * m_pValuesGB;
- Q3ButtonGroup * m_pScopeBG;
+ QGroupBox * m_pValuesGB;
+ QGroupBox * m_pScopeGB;
QRadioButton * m_pPublicRB, * m_pPrivateRB, * m_pProtectedRB, * m_pImplementationRB;
QLabel * m_pTypeL, * m_pNameL, * m_pInitialL, * m_pStereoTypeL;
KComboBox * m_pTypeCB;
More information about the umbrello-devel
mailing list