From 3b3b84fd99503414c0526619070f640cd0cb53dd Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Mon, 9 Jun 2014 17:37:04 +0200 Subject: [PATCH] now, action("set") and action("setint") check the number of given value (and ask for it otherwise) --- mainwindow.cpp | 86 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 9717e5d..c02dfc8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -156,6 +156,7 @@ void MainWindow::action(const QString &a){ QStringList b=a.split(QString(" ")); QString c=a; c.remove(0,4); + int bs=b.size(); int part=a.count(conf->value(QString("sepcmd")).toString()); if(part){ for(int d=0; d<=part; d++){ @@ -163,17 +164,49 @@ void MainWindow::action(const QString &a){ } } else if(b[0]==QString("set")){ - conf->setValue(b[1], b[2]); - } - else if(b[0]==QString("settext")){ + QString d, e; bool ok; - QString e=QInputDialog::getText(this, "setText", b[1], QLineEdit::Normal, conf->value(b[1]).toString(), &ok); - if(ok)conf->setValue(b[1], e); + if(bs==1){ + d=QInputDialog::getText(this, "set", trUtf8("Variable's name ?", "text to ask value's name before changing it (set)"), QLineEdit::Normal, QString(""), &ok); + if(!ok)return; + e=QInputDialog::getText(this, "set", d, QLineEdit::Normal, conf->value(d).toString(), &ok); + if(!ok)return; + }else if(bs==2){ + d=b[1]; + e=QInputDialog::getText(this, "set", d, QLineEdit::Normal, conf->value(d).toString(), &ok); + if(!ok)return; + }else if(bs==3){ + d=b[1]; + e=b[2]; + }else{ + QMessageBox::critical(this, trUtf8("Error","title if action(\"set\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"set\") has too much value")); + return; + } + QMessageBox::information(this, trUtf8("variable text change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change")); + conf->setValue(d, e); } else if(b[0]==QString("setint")){ bool ok; - int e=QInputDialog::getInt(this, "setInt", b[1] , conf->value(QString(b[1])).toInt(), 0, 100, 1, &ok); - if(ok)conf->setValue(b[1], e); + int e; + QString d; + if(bs==1){ + d=QInputDialog::getText(this, "setInt", trUtf8("Variable's name ?", "text to ask value's name before changing it (setint)") , QString(""), 0, 100, 1, &ok); + if(!ok)return; + e=QInputDialog::getInt(this, "setInt", d, QLineEdit::Normal, conf->value(d).toInt(), &ok); + if(!ok)return; + }else if(bs==2){ + d=b[1]; + e=QInputDialog::getInt(this, "setInt", b[1] , conf->value(QString(d)).toInt(), 0, 100, 1, &ok); + if(!ok)return; + }else if(bs==3){ + d=b[1]; + e=b[2].toInt(); + }else{ + QMessageBox::critical(this, trUtf8("Error","title if action(\"set\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"set\") has too much value")); + return; + } + QMessageBox::information(this, trUtf8("variable integer change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change")); + conf->setValue(d, e); } else if(b[0]==QString("start")){ start(); @@ -194,8 +227,20 @@ void MainWindow::action(const QString &a){ } else if(b[0]==QString("setfile")){ bool ok=0; - QString e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(b[1]).toString()); - if(ok)conf->setValue(b[1], e); + QString d, e; + if(bs==1){ + d=QInputDialog::getText(this, "setInt", trUtf8("Variable's name ?", "text to ask value's name before changing it (setint)") , QString(""), 0, 100, 1, &ok); + if(!ok)return; + e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(d).toString()); + }else if(bs==2){ + d=b[1]; + e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(d).toString()); + }else if(bs==3){ + d=b[1]; + e=b[2]; + } + QMessageBox::information(this, trUtf8("variable file change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change")); + conf->setValue(d, e); } else if(b[0]==QString("box")){ QMessageBox::information(this, trUtf8("box", "box title to show a text"), c); @@ -223,11 +268,18 @@ void MainWindow::action(const QString &a){ else if(b[0]==QString("edit")){ QString e; bool ok; - if(b.size()<=1){ + if(bs==1){ e=QInputDialog::getText(this, QString("ID"), trUtf8("Enter ID of button to edit"), QLineEdit::Normal, QString(""), &ok); - if(ok)editButtonDB(e); + if(!ok)return; } - else editButtonDB(b[1]); + else if(bs==2){ + e=b[1]; + } + else{ + QMessageBox::critical(this, trUtf8("Error","title if action(\"edit\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"edit\") has too much value")); + return; + } + editButtonDB(e); } else if(b[0]==QString("but")){ @@ -275,9 +327,13 @@ void MainWindow::action(const QString &a){ way.removeAt(b[1].toInt()); } else if(b[0]==QString("read")){ - QFile a(b[1]); - a.open(QIODevice::ReadOnly); - readData(a.readAll()); + if(bs==2){ + QFile a(b[1]); + a.open(QIODevice::ReadOnly); + readData(a.readAll()); + }else{ + QMessageBox::warning(this, trUtf8("Error", "title of box if action(\"read\" hasn't too much value")); + } } else { getButtons(a); -- 2.45.1