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

List:       kde-commits
Subject:    koffice/kspread/functions
From:       Marijn Kruisselbrink <m.kruisselbrink () student ! tue ! nl>
Date:       2010-06-13 11:59:36
Message-ID: 20100613115936.ECFB5AC8D4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1137534 by mkruisselbrink:

fix support for multiple conditions on the same cell in one row in the database functions


 M  +12 -11    database.cpp  


--- trunk/koffice/kspread/functions/database.cpp #1137533:1137534
@@ -147,13 +147,13 @@
 private:
     void parse(Value conds);
     ValueCalc *calc;
-    Condition **cond;
+    QList<QList<Condition*> > cond;
     int rows, cols;
     Value db;
 };
 
 DBConditions::DBConditions(ValueCalc *vc, Value database,
-                           Value conds) : calc(vc), cond(0), rows(0), cols(0), db(database)
+                           Value conds) : calc(vc), rows(0), cols(0), db(database)
 {
     parse(conds);
 }
@@ -162,8 +162,7 @@
 {
     int count = rows * cols;
     for (int r = 0; r < count; ++r)
-        delete cond[r];
-    delete[] cond;
+        qDeleteAll(cond[r]);
 }
 
 void DBConditions::parse(Value conds)
@@ -177,9 +176,8 @@
     if(count <= 0)
         return;
 
-    cond = new Condition* [count];
     for (int r = 0; r < count; ++r)
-        cond[r] = 0;
+        cond.append(QList<Condition*>());
 
     // perform the parsing itself
     int cc = conds.columns();
@@ -193,9 +191,10 @@
             Value cnd = conds.element(c, r + 1);
             if (cnd.isEmpty()) continue;
             int idx = r * cols + col;
-            if (cond[idx]) delete cond[idx];
-            cond[idx] = new Condition;
-            calc->getCond(*cond[idx], cnd);
+            //if (cond[idx]) delete cond[idx];
+            Condition* theCond = new Condition;
+            calc->getCond(*theCond, cnd);
+            cond[idx].append(theCond);
         }
     }
 }
@@ -211,12 +210,14 @@
         bool match = true;
         for (int c = 0; c < cols; ++c) {
             int idx = r * cols + c;
-            if (!cond[idx]) continue;
-            if (!calc->matches(*cond[idx], db.element(c, row + 1))) {
+            if (cond[idx].isEmpty()) continue;
+            for (int i = 0; i < cond[idx].size(); i++) {
+                if (!calc->matches(*cond[idx][i], db.element(c, row + 1))) {
                 match = false;  // didn't match
                 break;
             }
         }
+        }
         if (match)  // all conditions in this row matched
             return true;
     }
[prev in list] [next in list] [prev in thread] [next in thread] 

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