[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kexi/koproperty2/koproperty
From:       Adam Pigg <adam () piggz ! co ! uk>
Date:       2009-03-19 8:45:15
Message-ID: 1237452315.745289.8660.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 941263 by piggz:

Make the double property unit aware.


 M  +1 -1      CMakeLists.txt  
 M  +4 -1      EditorView.cpp  
 M  +2 -2      editors/combobox.cpp  
 M  +33 -3     editors/spinbox.cpp  
 M  +4 -2      editors/spinbox.h  


--- trunk/koffice/kexi/koproperty2/koproperty/CMakeLists.txt #941262:941263
@@ -51,7 +51,7 @@
 kde4_add_library(koproperty2 SHARED ${koproperty_LIB_SRCS})
 
 target_link_libraries(koproperty2
-#  koguiutils
+  koguiutils
   ${KDE4_KDE3SUPPORT_LIBS}
 )
 
--- trunk/koffice/kexi/koproperty2/koproperty/EditorView.cpp #941262:941263
@@ -320,7 +320,10 @@
         if (index.isValid()) {
             Property *property = d->model->propertyForItem(index);
             //TODO This crashes when changing the interpreter type in the script \
                plugin
-            //d->set->setPreviousSelection(property->name()); 
+            //if (property->isNull())
+            //    kDebug() << "WTF? a NULL property?";
+            //else        
+                //d->set->setPreviousSelection(property->name()); 
         }
         else {
             d->set->setPreviousSelection(QByteArray());
--- trunk/koffice/kexi/koproperty2/koproperty/editors/combobox.cpp #941262:941263
@@ -268,9 +268,9 @@
         return property->value().toString();
     if (property->value().isNull())
         return QString();
-    kDebug() << "property->value()==" << property->value();
+    //kDebug() << "property->value()==" << property->value();
     const int idx = listData->keys.indexOf( property->value() );
-    kDebug() << "idx==" << idx;
+    //kDebug() << "idx==" << idx;
     if (idx == -1)
         return QString();
     return property->listData()->names[ idx ];
--- trunk/koffice/kexi/koproperty2/koproperty/editors/spinbox.cpp #941262:941263
@@ -35,6 +35,7 @@
 #include <QKeyEvent>
 #include <QEvent>
 #include <QLineEdit>
+#include <KoUnit.h>
 
 using namespace KoProperty;
 
@@ -235,6 +236,7 @@
 DoubleSpinBox::DoubleSpinBox(const Property* prop, QWidget *parent)
         : KDoubleNumInput(parent)
 {
+    _p = prop;
     QDoubleSpinBox* sb = findChild<QDoubleSpinBox*>();
     QLineEdit* le = 0;
     if (sb)
@@ -295,6 +297,25 @@
     KDoubleNumInput::resizeEvent(event);
 }
 
+void DoubleSpinBox::setValue(double v)
+{
+    if (_p->option("unit", "").toString().isEmpty()) {
+        KDoubleNumInput::setValue(v);
+    }else {
+        KDoubleNumInput::setValue(KoUnit::unit(_p->option("unit").toString()).toUserValue(v));
 +    }
+}
+
+double DoubleSpinBox::value() const
+{
+    if (_p->option("unit", "").toString().isEmpty()) {
+        return KDoubleNumInput::value();
+    }
+    else {
+        return KoUnit::unit(_p->option("unit").toString()).fromUserValue(KDoubleNumInput::value());
 +    }
+}
+
 /*
 bool
 DoubleSpinBox::eventFilter(QObject *o, QEvent *e)
@@ -437,6 +458,8 @@
 }
 */
 
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 +
 //-----------------------
 
 IntSpinBoxDelegate::IntSpinBoxDelegate()
@@ -483,12 +506,19 @@
         if (!minValue.isNull() && !minValueText.isEmpty()
             && minValue.toDouble() == prop->value().toDouble())
         {
-            return minValueText;
+            return minValueText + " " + prop->option("unit").toString();
         }
     }
 //! @todo precision? 
 //! @todo rounding using KLocale::formatNumber(const QString &numStr, bool round = \
                true,int precision = 2)?
-    return KGlobal::locale()->formatNumber(prop->value().toDouble());
+    QString display;
+    if (prop->option("unit", "").toString().isEmpty()) {
+        display = KGlobal::locale()->formatNumber(prop->value().toDouble());
+    }
+    else {
+        display = KGlobal::locale()->formatNumber(KoUnit::unit(prop->option("unit").toString()).toUserValue(prop->value().toDouble())) \
+ " " + prop->option("unit").toString(); +    }
+    return display;
 }
 
 QWidget* DoubleSpinBoxDelegate::createEditor( int type, QWidget *parent, 
@@ -499,5 +529,5 @@
     Property *prop = editorModel->propertyForItem(index);
     return new DoubleSpinBox(prop, parent);
 }
-
+                                              
 #include "spinbox.moc"
--- trunk/koffice/kexi/koproperty2/koproperty/editors/spinbox.h #941262:941263
@@ -101,17 +101,19 @@
         return QDoubleSpinBox::lineEdit();
     }*/
 
-    virtual double value() const { return KDoubleNumInput::value(); }
+    virtual double value() const;
 
 signals:
     void commitData( QWidget * editor );
 
 public slots:
-    virtual void setValue(double value) { KDoubleNumInput::setValue(value); }
+    virtual void setValue(double value);
 
 protected:
     //! Used to fix height of the internal spin box
     virtual void resizeEvent( QResizeEvent * event );
+private:
+        const Property *_p;
 };
 
 /*


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic