[Kst] extragear/graphics/kst/src

Eli Fidler eli at staikos.net
Tue Jan 9 22:26:50 CET 2007


SVN commit 621836 by fidler:

redo string selector based on scalar selector

new icons for string selector


 M  +1 -0      kst/pics/Makefile.am  
 AM            kst/pics/kst_stringedit.png  
 AM            kst/pics/kst_stringnew.png  
 A             kst/pics/svg_icons/edit_string.svg  
 A             kst/pics/svg_icons/new_string.svg  
 M  +7 -2      libkst/kststring.cpp  
 M  +4 -0      libkst/kststring.h  
 M  +63 -31    widgets/stringselector.ui  
 M  +121 -26   widgets/stringselector.ui.h  


--- trunk/extragear/graphics/kst/src/kst/pics/Makefile.am #621835:621836
@@ -9,6 +9,7 @@
 	kst_datawizard.png kst_vectornew.png kst_vectoredit.png \
 	kst_matrixedit.png kst_matrixnew.png \
 	kst_scalaredit.png kst_scalarnew.png \
+	kst_stringedit.png kst_stringnew.png \
 	kst_curvenew.png kst_psdnew.png kst_histogramnew.png\
 	kst_equationnew.png kst_imagenew.png kst_pluginnew.png \
 	kst_eventnew.png kst_graphics.png kst_gfx_line.png \
** trunk/extragear/graphics/kst/src/kst/pics/kst_stringedit.png #property svn:mime-type
   + application/octet-stream
** trunk/extragear/graphics/kst/src/kst/pics/kst_stringnew.png #property svn:mime-type
   + application/octet-stream
--- trunk/extragear/graphics/kst/src/libkst/kststring.cpp #621835:621836
@@ -25,7 +25,7 @@
 static int anonymousStringCounter = 0;
 
 KstString::KstString(KstObjectTag in_tag, KstObject *provider, const QString& val, bool orphan)
-: KstPrimitive(provider), _value(val), _orphan(orphan) {
+: KstPrimitive(provider), _value(val), _orphan(orphan), _editable(false) {
   QString _tag = in_tag.tag();
   if (!in_tag.isValid()) {
     QString nt = i18n("Anonymous String %1");
@@ -45,7 +45,7 @@
 
 
 KstString::KstString(QDomElement& e)
-: KstPrimitive(), _orphan(false) {
+: KstPrimitive(), _orphan(false), _editable(false) {
   QDomNode n = e.firstChild();
 
   while (!n.isNull()) {
@@ -57,6 +57,8 @@
         _orphan = true;
       } else if (e.tagName() == "value") {
         setValue(e.text());
+      } else if (e.tagName() == "editable") {
+        _editable = true;
       }
     }
     n = n.nextSibling();
@@ -81,6 +83,9 @@
   if (_orphan) {
     ts << indent << "<orphan/>" << endl;
   }
+  if (_editable) {
+    ts << indent << "<editable/>" << endl;
+  }
   ts << indent << "<value>" << QStyleSheet::escape(value()) << "</value>" << endl;
 }
 
--- trunk/extragear/graphics/kst/src/libkst/kststring.h #621835:621836
@@ -53,12 +53,16 @@
     bool orphan() const { return _orphan; }
     void setOrphan(bool orphan) { _orphan = orphan; }
 
+    bool editable() const { return _editable; }
+    void setEditable(bool editable) { _editable = editable; }
+
   signals:
     void trigger();
 
   private:
     QString _value;
     bool _orphan : 1;
+    bool _editable;
 };
 
 typedef KstSharedPtr<KstString> KstStringPtr;
--- trunk/extragear/graphics/kst/src/widgets/stringselector.ui #621835:621836
@@ -1,4 +1,4 @@
-<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
 <class>StringSelector</class>
 <widget class="QWidget">
     <property name="name">
@@ -9,25 +9,47 @@
             <x>0</x>
             <y>0</y>
             <width>328</width>
-            <height>32</height>
+            <height>38</height>
         </rect>
     </property>
     <property name="whatsThis" stdset="0">
         <string>Select a string to utilize.  If you wish to create a new string, select the icon to the right.</string>
     </property>
-    <hbox>
+    <grid>
         <property name="name">
             <cstring>unnamed</cstring>
         </property>
         <property name="margin">
             <number>0</number>
         </property>
-        <widget class="QComboBox">
+        <widget class="QPushButton" row="0" column="3">
             <property name="name">
+                <cstring>_editString</cstring>
+            </property>
+            <property name="enabled">
+                <bool>false</bool>
+            </property>
+            <property name="sizePolicy">
+                <sizepolicy>
+                    <hsizetype>0</hsizetype>
+                    <vsizetype>0</vsizetype>
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                </sizepolicy>
+            </property>
+            <property name="text">
+                <string></string>
+            </property>
+            <property name="toolTip" stdset="0">
+                <string>Edit selected string.</string>
+            </property>
+        </widget>
+        <widget class="QComboBox" row="0" column="0">
+            <property name="name">
                 <cstring>_string</cstring>
             </property>
         </widget>
-        <widget class="QPushButton">
+        <widget class="QPushButton" row="0" column="2">
             <property name="name">
                 <cstring>_newString</cstring>
             </property>
@@ -42,47 +64,54 @@
             <property name="text">
                 <string></string>
             </property>
-            <property name="pixmap">
-                <pixmap>image0</pixmap>
-            </property>
             <property name="toolTip" stdset="0">
                 <string>Create a new string.</string>
             </property>
         </widget>
-    </hbox>
+        <widget class="QPushButton" row="0" column="1">
+            <property name="name">
+                <cstring>_selectString</cstring>
+            </property>
+            <property name="sizePolicy">
+                <sizepolicy>
+                    <hsizetype>0</hsizetype>
+                    <vsizetype>0</vsizetype>
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                </sizepolicy>
+            </property>
+            <property name="maximumSize">
+                <size>
+                    <width>32</width>
+                    <height>32</height>
+                </size>
+            </property>
+            <property name="text">
+                <string>...</string>
+            </property>
+        </widget>
+    </grid>
 </widget>
-<images>
-    <image name="image0">
-        <data format="XPM.GZ" length="454">789c6d90c10ac2300c40effd8ad0dc8a7416410ae227281e05f1d0b5821ea6a0f320e2bfdba45dd5ba642d798fa45bd728d86e56a01a71eb5d7ff2e08fee0a2adcbbeeb1db2f9f429a39c4276e7222a4060febcbf940b58b354e39085b46434918182d25a12734334a4224b471d2f2acae223bc4cc5424571497d97d4d66c76dcea585589c4bd11617db3c77716371341dd2813f4effb950bb7c96ff381c5e5b7f4b5a831bbbc7e87dabfff25a8837eb4358d8</data>
-    </image>
-</images>
-<connections>
-    <connection>
-        <sender>_newString</sender>
-        <signal>clicked()</signal>
-        <receiver>StringSelector</receiver>
-        <slot>createNewString()</slot>
-    </connection>
-    <connection>
-        <sender>_string</sender>
-        <signal>activated(const QString&amp;)</signal>
-        <receiver>StringSelector</receiver>
-        <slot>selectionWatcher(const QString&amp;)</slot>
-    </connection>
-</connections>
+<tabstops>
+    <tabstop>_string</tabstop>
+    <tabstop>_selectString</tabstop>
+    <tabstop>_newString</tabstop>
+    <tabstop>_editString</tabstop>
+</tabstops>
 <includes>
-    <include location="local" impldecl="in declaration">kststring.h</include>
+    <include location="local" impldecl="in declaration">comboboxselection_i.h</include>
     <include location="local" impldecl="in declaration">kstdatacollection.h</include>
     <include location="local" impldecl="in implementation">stringeditor.h</include>
     <include location="global" impldecl="in implementation">qlineedit.h</include>
     <include location="global" impldecl="in implementation">qvalidator.h</include>
     <include location="global" impldecl="in implementation">kmessagebox.h</include>
+    <include location="global" impldecl="in implementation">kiconloader.h</include>
     <include location="global" impldecl="in implementation">qlistbox.h</include>
     <include location="global" impldecl="in implementation">qtimer.h</include>
+    <include location="local" impldecl="in implementation">enodes.h</include>
+    <include location="global" impldecl="in declaration">kst_export.h</include>
     <include location="local" impldecl="in implementation">stringselector.ui.h</include>
-    <include location="global" impldecl="in declaration">kst_export.h</include>
 </includes>
-<exportmacro>KST_EXPORT</exportmacro>
 <signals>
     <signal>newStringCreated()</signal>
     <signal>selectionChanged(const QString&amp;)</signal>
@@ -92,6 +121,8 @@
     <slot>allowNewStrings( bool allowed )</slot>
     <slot>update()</slot>
     <slot>createNewString()</slot>
+    <slot>selectString()</slot>
+    <slot>editString()</slot>
     <slot>selectionWatcher( const QString &amp; tag )</slot>
     <slot>setSelection( const QString &amp; tag )</slot>
     <slot>setSelection( KstStringPtr s )</slot>
@@ -101,5 +132,6 @@
     <function access="private">init()</function>
     <function returnType="QString">selectedString()</function>
 </functions>
+<exportmacro>KST_EXPORT</exportmacro>
 <layoutdefaults spacing="6" margin="11"/>
 </UI>
--- trunk/extragear/graphics/kst/src/widgets/stringselector.ui.h #621835:621836
@@ -7,6 +7,18 @@
 ** place of a destructor.
 *****************************************************************************/
 
+void StringSelector::init()
+{
+    update();
+    _newString->setPixmap(BarIcon("kst_stringnew"));
+    _editString->setPixmap(BarIcon("kst_stringedit"));
+    connect(_selectString, SIGNAL(clicked()), this, SLOT(selectString()));
+    connect(_newString, SIGNAL(clicked()), this, SLOT(createNewString()));
+    connect(_editString, SIGNAL(clicked()), this, SLOT(editString()));
+    connect(_string, SIGNAL(activated(const QString&)), this, SIGNAL(selectionChanged(const QString&)));
+    connect(_string, SIGNAL(textChanged(const QString&)), this, SIGNAL(selectionChanged(const QString&)));
+    connect(this, SIGNAL(selectionChanged(const QString&)), this, SLOT(selectionWatcher(const QString&)));
+}
 
 void StringSelector::allowNewStrings( bool allowed )
 {
@@ -21,55 +33,146 @@
     }
 
     blockSignals(true);
+    
     QString prev = _string->currentText();
     bool found = false;
+    QStringList strings;
+    
     _string->clear();
-
+    
 	KST::stringList.lock().readLock();
     for (KstStringList::Iterator i = KST::stringList.begin(); i != KST::stringList.end(); ++i) {
 		(*i)->readLock();
-		QString tag = (*i)->tag().displayString();
+	    QString tag = (*i)->tag().displayString();
+		strings << tag;
 		(*i)->unlock();
-		_string->insertItem(tag);
-		if (tag == prev) {
-			found = true;
-		}
-	}
+
+        if (tag == prev) {
+            found = true;
+        }
+    }
 	KST::stringList.lock().unlock();
-
-	if (found) {
-		_string->setCurrentText(prev);
-	}
+    
+    qHeapSort(strings);
+    _string->insertStringList(strings);
+    if (found) {
+        _string->setCurrentText(prev);
+    }
+    
     blockSignals(false);
 }
 
 void StringSelector::createNewString()
 {
     StringEditor *se = new StringEditor(this, "string editor");
+    
     int rc = se->exec();
     if (rc == QDialog::Accepted) {
-	KstStringPtr s = new KstString(KstObjectTag(se->_name->text(), KstObjectTag::globalTagContext), 0L, se->_value->text());
-	s->setOrphan(true);
-	emit newStringCreated();
-	update();
-	setSelection(s);
+        bool ok = false;
+        double val = se->_value->text().toFloat(&ok);
+        
+ 	if (!ok) {
+	    val = Equation::interpret(se->_value->text().latin1(), &ok);
+	}
+
+        if (ok) {
+            KstStringPtr s = new KstString(KstObjectTag(se->_name->text(), KstObjectTag::globalTagContext), 0L);
+            
+            s->setOrphan(true);
+            s->setEditable(true);
+            emit newStringCreated();
+            update();
+            setSelection(s);
+            _editString->setEnabled(true);
+        } else {
+            KMessageBox::sorry(this, tr("Error saving your new string."), tr("Kst"));
+        }
     }
+    
     delete se;
 }
 
+void StringSelector::selectString()
+{
+    ComboBoxSelectionI *selection = new ComboBoxSelectionI(this, "string selector");
+    int i;
+    
+    selection->reset();
+    for (i=0; i<_string->count(); i++) {
+        selection->addString(_string->text(i));
+    }
+    selection->sort();
+    int rc = selection->exec();
+    if (rc == QDialog::Accepted) {        
+        _string->setCurrentText(selection->selected());   
+    }
+    
+    delete selection;
+}
+
+void StringSelector::editString()
+{
+    StringEditor *se = new StringEditor(this, "string editor");
+    
+    KstStringPtr pold = *KST::stringList.findTag(_string->currentText());
+    if (pold && pold->editable()) { 
+        se->_value->setText(pold->value());
+        se->_name->setText(pold->tag().tagString()); 
+        se->_value->selectAll();
+        se->_value->setFocus();      
+    }
+    
+    int rc = se->exec();
+    if (rc == QDialog::Accepted) {
+        bool ok = false;
+        QString val = se->_value->text();
+
+        if (ok) {
+            KstStringPtr p = *KST::stringList.findTag(se->_name->text());
+            if (p) {
+                p->setValue(val);
+                setSelection(p);
+            } else {
+                p = new KstString(KstObjectTag(se->_name->text(), KstObjectTag::globalTagContext), 0L, val);
+
+                p->setOrphan(true);
+                p->setEditable(true);
+                emit newStringCreated();
+                update();
+                setSelection(p);
+                _editString->setEnabled(true);
+            }
+        } else {
+            KMessageBox::sorry(this, tr("Error saving your new string."), tr("Kst"));
+        }
+    }
+    
+    delete se;
+}
+
 void StringSelector::selectionWatcher( const QString & tag )
-{
+{   
+    bool editable = false;
+
     QString label = "["+tag+"]";
     emit selectionChangedLabel(label);
+    KST::stringList.lock().readLock();
+    KstStringPtr p = *KST::stringList.findTag(tag);
+    if (p && p->editable()) {
+      editable = true;
+    }
+    KST::stringList.lock().unlock();
+    _editString->setEnabled(editable);
 }
 
 void StringSelector::setSelection( const QString & tag )
 {
     if (tag.isEmpty()) {
-	    return;
+        return;
     }
     blockSignals(true);
     _string->setCurrentText(tag);
+    selectionWatcher(tag);
     blockSignals(false);
 }
 
@@ -78,19 +181,11 @@
     setSelection(s->tagName());
 }
 
-void StringSelector::init()
-{
-    update();
-    connect(_string, SIGNAL(activated(const QString&)), this, SIGNAL(selectionChanged(const QString&)));
-}
-
-
 QString StringSelector::selectedString()
 {
     return _string->currentText();
 }
 
-
 void StringSelector::allowDirectEntry( bool allowed )
 {
     _string->setEditable(allowed);


More information about the Kst mailing list