]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
remove(QString, QString, QString) fixed, added a debug function,
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 17 Jun 2014 15:33:19 +0000 (17:33 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 17 Jun 2014 15:33:19 +0000 (17:33 +0200)
mainwindow.cpp
mainwindow.h

index a75d29cd7aecf55f7aa375e1ec6da6a350a22910..44bf4e37931077da0469de12588c812bba8a55aa 100644 (file)
@@ -51,6 +51,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
 
         conf->setValue(QString("first"), 1);
     };
+    deb=0;
     screen=new QWidget(this);
     screen->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
     grid=new QGridLayout(screen);
@@ -154,6 +155,7 @@ const CLabel* MainWindow::addWidget(const QString &key, const CLabel *a){
 }
 void MainWindow::action(const QString &a){
     qDebug()<<"action("<<a<<")";
+    if(deb)QMessageBox::information(this, trUtf8("action", "box title to debug action"), a);
     QStringList b=a.split(QString(" "));
     QString c=a;
     bool ok;
@@ -226,15 +228,17 @@ void MainWindow::action(const QString &a){
         sav(c);
     }
     else if(b[0]==QString("back")){
-        if(way.size()>1){
+        if(way.size()>=1){
             int e;
             if(bs>1)e=b[2].toInt(&ok);
             else e=1;
             for(int bcl=0;bcl<e;bcl++){
                 way.removeLast();
             }
-            get(QString("buttons"), way.takeLast());
+        }else{
+            return;
         }
+        get(QString("buttons"), way.takeLast());
     }
     else if(b[0]==QString("setfile")){
         bool ok=0;
@@ -351,11 +355,13 @@ void MainWindow::action(const QString &a){
         }
     }
     else if(b[0]==QString("mass")){
-        if(bs==4){
-            int tmp=b[1].toInt();
-            mass(tmp, b[2], b[3]);
+        if(bs==5){
+            mass(b[1], b[2], b[3], b[4]);
         }
     }
+    else if(b[0]==QString("debug")){
+        debug();
+    }
     else {
         get(QString("buttons"),a);
 
@@ -430,14 +436,14 @@ void CLabel::mouseReleaseEvent( QMouseEvent * event )
 
     }
 }
-void MainWindow::debug(int col){
+/*void MainWindow::debug(int col){
     q->first();
     while(q->isValid()){
         int k=q->at();
         qDebug()<<"n°"<<k<<"="<<get(col);
         q->next();
     }
-}
+}*/
 void MainWindow::connectDB(){
     db = QSqlDatabase::addDatabase("QSQLITE");
     //db = QSqlDatabase::addDatabase("QPSQL");
@@ -463,7 +469,7 @@ void MainWindow::firstrun(){
     conf->setValue(QString("maxcolumn"), QVariant(2));
     conf->setValue(QString("maxline"), QVariant(3));
     conf->setValue(QString("SQLsettings"), QVariant("connect_timeout=10000"));
-    conf->setValue(QString("button"), QVariant("background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;"));
+    conf->setValue(QString("button"), QVariant("background-color: res;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;"));
     conf->setValue(QString("buttonbefore"), QVariant("border-style: outset"));
     conf->setValue(QString("buttonafter"), QVariant("border-style: inset"));
     conf->setValue(QString("menu"), QVariant(0));
@@ -877,9 +883,9 @@ void MainWindow::remove(const QString & a, const QString & keyword, const QStrin
         key=key+" "+cur;
     }
     qDebug()<<"key="<<key<<" keyword="<<keyword;
-    if((key==QString(" ").repeated(key.size()))||(key==keyword))exec(QList<QString>({conf->value(QString("delete")+a).toString(), id}));
+    key.replace(keyword, QString(""));
+    if(key==QString(" ").repeated(key.size()))exec(QList<QString>({conf->value(QString("delete")+a).toString(), id}));
     else{
-        key.replace(keyword, QString(""));
         exec(QList<QString>({conf->value(QString("updatebuttons")).toString(), key, label, action, id}));
     }
 }
@@ -958,22 +964,23 @@ void MainWindow::action(){
     QString cmd=QInputDialog::getText(this, trUtf8("action", "Title of box where ask for a custom action"), trUtf8("Enter your action", "Label of box where ask for custom action"), QLineEdit::Normal, QString(""), &ok);
     if(ok)action(cmd);
 }
-void MainWindow::mass(int c, const QString & a, const QString & b){
-    exec(QList<QString>({conf->value(QString("changekeyword")).toString(), a}));
+void MainWindow::mass(const QString & type, const QString & column, const QString & before, const QString & after){
+    exec(QList<QString>({conf->value(QString("change")+type).toString(), column}));
     QString key;
     while(q->next()){
-        key=get(c);
-        if(key.contains(a)){
-            key.replace(a,b);
-            QList<QString> tmp({conf->value(QString("updatebuttons")).toString()});
-            for(int t=0;t<4;t++){//4 is conf("changekey") column
-                if(t==c)tmp.append(key);
+        int n=q->record().indexOf(column);
+        key=get(n);
+        if(key.contains(before)){
+            key.replace(before, after);
+            QList<QString> tmp({conf->value(QString("update")+type).toString()});
+            for(int t=0;t<q->record().count();t++){
+                if(t==n)tmp.append(key);
                 else tmp.append(get(t));
             }
             exec2(tmp);
         }
     }
-    get(QString("buttons"), lastprint);
+    get(type, lastprint);
 }
 void MainWindow::addDB(){
     addDB(QString("buttons"));
@@ -1003,3 +1010,8 @@ void MainWindow::readSQL(){
     }
     emit datafilled();
 }
+void MainWindow::debug(){
+    //deb=-deb;
+    if(deb)deb=0;
+    else deb=1;
+}
index bfd2af77f5e77767fe3ef389396d17feddf2489a..8e2afd62b40878a9079e4faf15c98c0d27636266 100644 (file)
@@ -134,8 +134,9 @@ public:
     const CLabel* addWidget(const QString &, const CLabel *);
     void resizeEvent(QResizeEvent *);
     void sav(const QString &);
-    void mass(int, const QString &, const  QString &);
+    void mass(const QString &, const QString &, const QString &, const  QString &);
     void downSQL(const QString &);
+    void debug();
 private slots:
     void readSQL();
     void tmpdown();
@@ -152,7 +153,6 @@ private slots:
     void createMenuBar();
     void toggleMenu();
     void flush();
-    void debug(int);
     void connectDB();
     void firstrun();
     QString get(int);
@@ -215,6 +215,7 @@ private:
     QNetworkAccessManager *net;
     QNetworkReply * rep;
     bool orientation;//0=portrait 1=paysage (size.width() > size.height())
+    bool deb;
     QVideoWidget * videoWidget;
 };