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

List:       kde-commits
Subject:    KDE/kdegraphics/kolourpaint/lgpl/generic
From:       Clarence Dang <dang () kde ! org>
Date:       2007-09-27 6:46:59
Message-ID: 1190875619.881974.29534.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 717557 by dang:

* Fix inverted check in SaveToFile() that led to only invalid colors being saved

* Remove <name> argument from ctor, since files are not opened in the
  ctor anymore and it would be wrong to have the name but not the flie
  content

* Clear name() in saveAs() - Collections stored in regular files have an empty name().

* Better and more APIDoc

* style



 M  +21 -17    kpColorCollection.cpp  
 M  +20 -6     kpColorCollection.h  


--- trunk/KDE/kdegraphics/kolourpaint/lgpl/generic/kpColorCollection.cpp #717556:717557
@@ -57,18 +57,17 @@
 class kpColorCollectionPrivate
 {
 public:
-    kpColorCollectionPrivate(const QString &name = QString ());
+    kpColorCollectionPrivate();
     kpColorCollectionPrivate(const kpColorCollectionPrivate&);
     ~kpColorCollectionPrivate() {}
+
     QList<ColorNode> colorList;
-
     QString name;
     QString desc;
     kpColorCollection::Editable editable;
 };
 
-kpColorCollectionPrivate::kpColorCollectionPrivate(const QString &_name)
-    : name(_name)
+kpColorCollectionPrivate::kpColorCollectionPrivate()
 {
 }
 
@@ -95,9 +94,9 @@
   return paletteList;
 }
 
-kpColorCollection::kpColorCollection(const QString &name)
+kpColorCollection::kpColorCollection()
 {
-  d = new kpColorCollectionPrivate(name);
+  d = new kpColorCollectionPrivate();
 }
 
 kpColorCollection::kpColorCollection(const kpColorCollection &p)
@@ -194,7 +193,7 @@
   }
 
   d->colorList = newColorList;
-  d->name = QString ();
+  d->name.clear ();
   d->desc = newDesc;
 
   KIO::NetAccess::removeTempFile (tempPaletteFilePath);
@@ -269,7 +268,7 @@
    foreach (const ColorNode &node, d->colorList)
    {
        // Added for KolourPaint.
-       if(node.color.isValid ())
+       if(!node.color.isValid ())
            continue;
 
        int r,g,b;
@@ -300,7 +299,7 @@
    if (url.isLocalFile ())
    {
        const QString filename = url.path ();
-    
+
         // sync: All failure exit paths _must_ call KSaveFile::abort() or
         //       else, the KSaveFile destructor will overwrite the file,
         //       <filename>, despite the failure.
@@ -387,14 +386,19 @@
         }
     }
 
+   d->name.clear ();
    return true;
 }
 
 bool
 kpColorCollection::saveKDE(QWidget *parent) const
 {
-   QString filename = KStandardDirs::locateLocal("config", "colors/" + d->name);
-   return saveAs (KUrl (filename), false/*no overwite prompt*/, parent);
+   const QString name = d->name;
+   QString filename = KStandardDirs::locateLocal("config", "colors/" + name);
+   const bool ret = saveAs (KUrl (filename), false/*no overwite prompt*/, parent);
+   // (d->name is wiped by saveAs()).
+   d->name = name;
+   return ret;
 }
 
 QString kpColorCollection::description() const
@@ -432,17 +436,17 @@
     return (int) d->colorList.count();
 }
 
-void kpColorCollection::resize(int amount)
+void kpColorCollection::resize(int newCount)
 {
-    if (amount == count())
+    if (newCount == count())
         return;
-    else if (amount < count())
+    else if (newCount < count())
     {
-        d->colorList.erase(d->colorList.begin() + amount, d->colorList.end());
+        d->colorList.erase(d->colorList.begin() + newCount, d->colorList.end());
     }
-    else if (amount > count())
+    else if (newCount > count())
     {
-         while(amount > count())
+         while(newCount > count())
          {
              const int ret = addColor(QColor(), QString()/*color name*/);
              Q_ASSERT(ret == count() - 1);
--- trunk/KDE/kdegraphics/kolourpaint/lgpl/generic/kpColorCollection.h #717556:717557
@@ -48,6 +48,9 @@
  * This class makes it easy to handle color collections, sometimes referred to
  * as "palettes". This class can read and write collections from and to a file.
  *
+ * Collections that are managed by KDE have a non-empty name().  Collections
+ * stored in regular files have an empty name().
+ *
  * This class uses the "GIMP" palette file format.
  *
  * @author Waldo Bastian (bastian@kde.org), Clarence Dang (dang@kde.org)
@@ -64,8 +67,11 @@
 
    /**
     * kpColorCollection constructor
+    *
+    * <name> argument removed for KolourPaint.
+    * Use openKDE() instead, which also has error handling.
     **/
-   explicit kpColorCollection(const QString &name=QString());
+   explicit kpColorCollection();
 
    /**
     * kpColorCollection copy constructor.
@@ -90,20 +96,27 @@
 
    // Same as open() but is given the name of a KDE palette, not a filename.
    //
-   // @param name The name of collection as returned by installedCollections()
+   // @param name The name of collection as returned by installedCollections().
+   //             name() is set to this.
    //
-   // Added for KolourPaint
+   // Added for KolourPaint.
    bool openKDE(const QString &name, QWidget *parent);
 
    // On failure, this prints an error dialog and returns false.
    // If the user cancels any presented overwrite dialog, it also returns false.
    // On success, it returns true.
    //
+   // The file can be overwritten without displaying any warning dialog, if
+   // <showOverwritePrompt> is set to false.
+   //
+   // name() is set to an empty string.
+   //
    // Added for KolourPaint.
    bool saveAs(const KUrl &url, bool showOverwritePrompt, QWidget *parent) const;
 
    /**
-    * Save the collection
+    * Save the collection to the KDE-local store
+    * (usually $HOME/.kde/share/config/colors) using name().
     *
     * @return 'true' if successful
     *
@@ -164,13 +177,14 @@
    int count() const;
 
    /**
-    * Adds invalid colors or removes colors so that there will be @p amount
+    * Adds invalid colors or removes colors so that there will be @p newCount
     * colors in the color collection.
+    *
     * @param target number of colors
     *
     * Added for KolourPaint.
     */
-   void resize(int amount);
+   void resize(int newCount);
 
    /**
     * Find color by index.
[prev in list] [next in list] [prev in thread] [next in thread] 

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