]> git.cworth.org Git - vogl/commitdiff
UI: Update trim dialog so that it does not accept invalid input.
authorPeterLValve <peterl@valvesoftware.com>
Mon, 24 Mar 2014 19:07:58 +0000 (12:07 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 1 Apr 2014 19:37:32 +0000 (12:37 -0700)
* Clicking "OK" with invalid input would not set the member variables, but would return as accepted, resulting in a failed trim.
* Improved error messages if trim_frame or trim_len are invalid, and also now prompt the user if the entered trim_file already exists.

src/vogleditor/vogleditor_qtrimdialog.cpp
src/vogleditor/vogleditor_qtrimdialog.h
src/vogleditor/vogleditor_qtrimdialog.ui

index 6a4db8d9d0eda86eb261de03e7522c52d33527f7..aeeef6aac93bd3de85175bcaa921d319e3e4a7d9 100644 (file)
@@ -1,6 +1,7 @@
 #include "vogleditor_qtrimdialog.h"
 #include "ui_vogleditor_qtrimdialog.h"
 #include <QFileDialog>
+#include <QMessageBox>
 
 vogleditor_QTrimDialog::vogleditor_QTrimDialog(QString parentTraceFile, uint maxFrameIndex, uint maxTrimLength, QWidget *parent) :
     QDialog(parent),
@@ -24,21 +25,53 @@ vogleditor_QTrimDialog::~vogleditor_QTrimDialog()
     delete ui;
 }
 
-void vogleditor_QTrimDialog::on_buttonBox_accepted()
+void vogleditor_QTrimDialog::on_buttonBox_clicked(QAbstractButton *button)
 {
-    // verify all input
-    bool bValidFrame = false;
-    uint tmpFrame = ui->trimFrameLineEdit->text().toUInt(&bValidFrame);
-    bValidFrame = bValidFrame && (tmpFrame <= m_maxFrameIndex);
+    if (button == ui->buttonBox->button(QDialogButtonBox::Ok))
+    {
+        // validate the trim start frame
+        bool bValidFrame = false;
+        uint tmpFrame = ui->trimFrameLineEdit->text().toUInt(&bValidFrame);
+        bValidFrame = bValidFrame && (tmpFrame <= m_maxFrameIndex);
 
-    bool bValidLen = false;
-    uint tmpLen = ui->trimLenLineEdit->text().toUInt(&bValidLen);
-    bValidLen = bValidLen && (tmpLen > 0 && tmpLen < m_maxTrimLength);
+        if (!bValidFrame)
+        {
+            QMessageBox::warning(this, tr("Invalid Trim Frame"), tr("Please enter a valid frame number at which to start the trim."),
+                                 QMessageBox::Ok, QMessageBox::Ok);
+            ui->trimFrameLineEdit->setFocus();
+            return;
+        }
 
-    bool bValidFile = (ui->trimFrameLineEdit->text().isEmpty() == false);
+        // validate the trim length
+        bool bValidLen = false;
+        uint tmpLen = ui->trimLenLineEdit->text().toUInt(&bValidLen);
+        bValidLen = bValidLen && (tmpLen > 0 && tmpLen <= m_maxTrimLength);
+
+        if (!bValidLen)
+        {
+            QMessageBox::warning(this, tr("Invalid Trim Count"), tr("Please enter a valid nubmer of frames to trim."),
+                                 QMessageBox::Ok, QMessageBox::Ok);
+            ui->trimLenLineEdit->setFocus();
+            return;
+        }
+
+        // validate the filename
+        QFile file(ui->trimFileLineEdit->text());
+        if (file.exists())
+        {
+            QString message = ui->trimFileLineEdit->text();
+            message += " already exits.\nWould you like to overwrite it?";
+            int ret = QMessageBox::warning(this, tr("File Already Exists"), tr(message.toStdString().c_str()),
+                                 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+
+            if (ret == QMessageBox::No)
+            {
+                // return so that the user can update the path
+                ui->trimFileLineEdit->setFocus();
+                return;
+            }
+        }
 
-    if (bValidFrame && bValidLen && bValidFile)
-    {
         m_trim_frame = ui->trimFrameLineEdit->text();
         m_trim_len = ui->trimLenLineEdit->text();
         m_trim_file = ui->trimFileLineEdit->text();
index a9ec3de046077a29890536f22bb7cf0780e0103c..a952cfb45c8cce8cebad642d8256ecb18577efae 100644 (file)
@@ -4,6 +4,8 @@
 #include <QDialog>
 #include <QString>
 
+class QAbstractButton;
+
 namespace Ui {
 class vogleditor_QTrimDialog;
 }
@@ -32,7 +34,7 @@ public:
     }
 
 private slots:
-    void on_buttonBox_accepted();
+    void on_buttonBox_clicked(QAbstractButton *button);
 
     void on_buttonBox_rejected();
 
index d9cef6ca6dc9a636c7d9d927f8a99e8683964dcb..485127318e4c9e1afa6a895470cf708af46f5d4a 100644 (file)
@@ -38,7 +38,7 @@
      <item>
       <widget class="QLabel" name="label_2">
        <property name="text">
-        <string>trim_frame:</string>
+        <string>trim_frame</string>
        </property>
       </widget>
      </item>
  </widget>
  <resources/>
  <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>vogleditor_QTrimDialog</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>248</x>
-     <y>254</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
   <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>