In EditSupplier backports from EditFermentables including a Delete button.

Sun, 20 Feb 2022 10:34:24 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 20 Feb 2022 10:34:24 +0100
changeset 21
15e5879df8dc
parent 20
fcbbddcc22c1
child 22
b52978ee7412

In EditSupplier backports from EditFermentables including a Delete button.

src/EditSupplier.cpp file | annotate | diff | comparison | revisions
src/EditSupplier.h file | annotate | diff | comparison | revisions
ui/EditSupplier.ui file | annotate | diff | comparison | revisions
--- a/src/EditSupplier.cpp	Sat Feb 19 22:17:09 2022 +0100
+++ b/src/EditSupplier.cpp	Sun Feb 20 10:34:24 2022 +0100
@@ -53,12 +53,15 @@
     connect(ui->emailEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed);
     connect(ui->phoneEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed);
     connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
+
+    ui->saveButton->setEnabled(false);
+    ui->deleteButton->setEnabled((id >= 0) ? true:false);
 }
 
 
 EditSupplier::~EditSupplier()
 {
-    qDebug() << "EditSupplier closed";
+    qDebug() << "EditSupplier done";
     delete ui;
     emit entry_changed();
 }
@@ -84,7 +87,7 @@
 }
 
 
-void EditSupplier::onOKButtonClicked()
+void EditSupplier::on_saveButton_clicked()
 {
     QSqlQuery query;
 
@@ -127,26 +130,61 @@
 	} else {
 	    qDebug() << "EditSupplier Saved";
 	}
+    }
 
-    	this->close();
-    	this->setResult(1);
+    ui->saveButton->setEnabled(false);
+    this->textIsChanged = false;
+    WindowTitle();
+}
+
+
+void EditSupplier::on_deleteButton_clicked()
+{
+    QSqlQuery query;
+
+    query.prepare("DELETE FROM inventory_suppliers WHERE record = :recno");
+    query.bindValue(":recno", this->recno);
+    query.exec();
+    if (query.lastError().isValid()) {
+        qDebug() << "EditSupplier" << query.lastError();
+        QMessageBox::warning(this, tr("Database error"),
+                        tr("MySQL error: %1\n%2\n%3")
+                        .arg(query.lastError().nativeErrorCode())
+                        .arg(query.lastError().driverText())
+                        .arg(query.lastError().databaseText()));
     } else {
-	/* Not saving */
-	this->close();
-	this->setResult(0);
+        qDebug() << "EditSupllier Deleted" << this->recno;
     }
+
+    this->close();
+    this->setResult(1);
 }
 
 
 void EditSupplier::is_changed()
 {
+    ui->saveButton->setEnabled(true);
     this->textIsChanged = true;
     WindowTitle();
 }
 
 
-void EditSupplier::onCancelButtonClicked()
+void EditSupplier::on_quitButton_clicked()
 {
+    if (this->textIsChanged) {
+        int rc = QMessageBox::warning(this, tr("Supplier changed"), tr("The supplier has been modified\n Save changes?"),
+                                QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
+        switch (rc) {
+            case QMessageBox::Save:
+                        on_saveButton_clicked();
+                        break;  /* Saved and then Quit */
+            case QMessageBox::Discard:
+                        break;  /* Quit without Save */
+            case QMessageBox::Cancel:
+                        return; /* Return to the editor page */
+        }
+    }
+
     this->close();
-    this->setResult(0);
+    this->setResult(1);
 }
--- a/src/EditSupplier.h	Sat Feb 19 22:17:09 2022 +0100
+++ b/src/EditSupplier.h	Sun Feb 20 10:34:24 2022 +0100
@@ -20,8 +20,9 @@
     ~EditSupplier();
 
 private slots:
-    void onOKButtonClicked();
-    void onCancelButtonClicked();
+    void on_saveButton_clicked();
+    void on_quitButton_clicked();
+    void on_deleteButton_clicked();
     void is_changed();
 
 private:
--- a/ui/EditSupplier.ui	Sat Feb 19 22:17:09 2022 +0100
+++ b/ui/EditSupplier.ui	Sun Feb 20 10:34:24 2022 +0100
@@ -16,196 +16,378 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QWidget" name="widget" native="true">
-     <layout class="QFormLayout" name="formLayout">
-      <item row="0" column="0">
-       <widget class="QLabel" name="nameLabel">
-        <property name="text">
-         <string>Name</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="QLineEdit" name="nameEdit">
-        <property name="maxLength">
-         <number>128</number>
-        </property>
-        <property name="placeholderText">
-         <string>Supplier name</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="0">
-       <widget class="QLabel" name="addressLabel">
-        <property name="text">
-         <string>Address</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="1">
-       <widget class="QLineEdit" name="addressEdit">
-        <property name="toolTip">
-         <string>The street and housenumber</string>
-        </property>
-        <property name="maxLength">
-         <number>128</number>
-        </property>
-        <property name="placeholderText">
-         <string>Address</string>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="0">
-       <widget class="QLabel" name="cityLabel">
-        <property name="text">
-         <string>City</string>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="1">
-       <widget class="QLineEdit" name="cityEdit">
-        <property name="maxLength">
-         <number>123</number>
-        </property>
-        <property name="placeholderText">
-         <string>City</string>
-        </property>
-       </widget>
-      </item>
-      <item row="3" column="0">
-       <widget class="QLabel" name="zipLabel">
-        <property name="text">
-         <string>Zip code</string>
-        </property>
-       </widget>
-      </item>
-      <item row="3" column="1">
-       <widget class="QLineEdit" name="zipEdit">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="maxLength">
-         <number>16</number>
-        </property>
-        <property name="placeholderText">
-         <string>Zip code</string>
-        </property>
-       </widget>
-      </item>
-      <item row="4" column="0">
-       <widget class="QLabel" name="countryLabel">
-        <property name="text">
-         <string>Country</string>
-        </property>
-       </widget>
-      </item>
-      <item row="4" column="1">
-       <widget class="QLineEdit" name="countryEdit">
-        <property name="maxLength">
-         <number>128</number>
-        </property>
-        <property name="placeholderText">
-         <string>Country</string>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="0">
-       <widget class="QLabel" name="webLabel">
-        <property name="text">
-         <string>Website</string>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="1">
-       <widget class="QLineEdit" name="webEdit">
-        <property name="maxLength">
-         <number>128</number>
-        </property>
-        <property name="placeholderText">
-         <string>https://www.supplier.com</string>
-        </property>
-       </widget>
-      </item>
-      <item row="6" column="0">
-       <widget class="QLabel" name="emailLabel">
-        <property name="text">
-         <string>Email</string>
-        </property>
-       </widget>
-      </item>
-      <item row="6" column="1">
-       <widget class="QLineEdit" name="emailEdit">
-        <property name="maxLength">
-         <number>128</number>
-        </property>
-        <property name="placeholderText">
-         <string>sales@supplier.com</string>
-        </property>
-       </widget>
-      </item>
-      <item row="7" column="0">
-       <widget class="QLabel" name="phoneLabel">
-        <property name="text">
-         <string>Phone</string>
-        </property>
-       </widget>
-      </item>
-      <item row="7" column="1">
-       <widget class="QLineEdit" name="phoneEdit">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="maxLength">
-         <number>16</number>
-        </property>
-        <property name="placeholderText">
-         <string>+31 123 45678</string>
-        </property>
-       </widget>
-      </item>
-      <item row="8" column="0">
-       <widget class="QLabel" name="notesLabel">
-        <property name="text">
-         <string>Notes</string>
-        </property>
-       </widget>
-      </item>
-      <item row="8" column="1">
-       <widget class="QPlainTextEdit" name="notesEdit">
-        <property name="horizontalScrollBarPolicy">
-         <enum>Qt::ScrollBarAlwaysOff</enum>
-        </property>
-        <property name="placeholderText">
-         <string>Notes about this supplier</string>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item>
-    <widget class="QDialogButtonBox" name="buttonBox">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons">
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-     </property>
-     <property name="centerButtons">
-      <bool>true</bool>
-     </property>
+    <widget class="QWidget" name="supWidget" native="true">
+     <widget class="QLabel" name="nameLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>10</y>
+        <width>91</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Name:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="addressLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>40</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Address:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="addressEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>40</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="toolTip">
+       <string>The street and housenumber</string>
+      </property>
+      <property name="maxLength">
+       <number>128</number>
+      </property>
+      <property name="placeholderText">
+       <string>Address</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="cityLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>70</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>City:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="cityEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>70</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="maxLength">
+       <number>123</number>
+      </property>
+      <property name="placeholderText">
+       <string>City</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="zipLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>100</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Zip code:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="zipEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>100</y>
+        <width>125</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="maxLength">
+       <number>16</number>
+      </property>
+      <property name="placeholderText">
+       <string>Zip code</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="countryLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>130</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Country:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="countryEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>130</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="maxLength">
+       <number>128</number>
+      </property>
+      <property name="placeholderText">
+       <string>Country</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="webLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>160</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Website:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="webEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>160</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="maxLength">
+       <number>128</number>
+      </property>
+      <property name="placeholderText">
+       <string>https://www.supplier.com</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="emailLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>190</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Email:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="emailEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>190</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="maxLength">
+       <number>128</number>
+      </property>
+      <property name="placeholderText">
+       <string>sales@supplier.com</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="phoneLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>220</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Phone:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="phoneEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>220</y>
+        <width>125</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="maxLength">
+       <number>16</number>
+      </property>
+      <property name="placeholderText">
+       <string>+31 123 45678</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="notesLabel">
+      <property name="geometry">
+       <rect>
+        <x>9</x>
+        <y>250</y>
+        <width>91</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Notes:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QPlainTextEdit" name="notesEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>250</y>
+        <width>761</width>
+        <height>131</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="horizontalScrollBarPolicy">
+       <enum>Qt::ScrollBarAlwaysOff</enum>
+      </property>
+      <property name="placeholderText">
+       <string>Notes about this supplier</string>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="nameEdit">
+      <property name="geometry">
+       <rect>
+        <x>110</x>
+        <y>10</y>
+        <width>761</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="maxLength">
+       <number>128</number>
+      </property>
+      <property name="placeholderText">
+       <string>Supplier name</string>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="quitButton">
+      <property name="geometry">
+       <rect>
+        <x>100</x>
+        <y>510</y>
+        <width>80</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Quit</string>
+      </property>
+      <property name="icon">
+       <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+        <normaloff>:/icons/silk/icons/silk/door_out.png</normaloff>:/icons/silk/icons/silk/door_out.png</iconset>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="saveButton">
+      <property name="geometry">
+       <rect>
+        <x>800</x>
+        <y>510</y>
+        <width>80</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Save</string>
+      </property>
+      <property name="icon">
+       <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+        <normaloff>:/icons/silk/icons/silk/disk.png</normaloff>:/icons/silk/icons/silk/disk.png</iconset>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="deleteButton">
+      <property name="geometry">
+       <rect>
+        <x>463</x>
+        <y>510</y>
+        <width>80</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Delete</string>
+      </property>
+      <property name="icon">
+       <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+        <normaloff>:/icons/silk/icons/silk/delete.png</normaloff>:/icons/silk/icons/silk/delete.png</iconset>
+      </property>
+     </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <tabstops>
-  <tabstop>nameEdit</tabstop>
   <tabstop>addressEdit</tabstop>
   <tabstop>cityEdit</tabstop>
   <tabstop>zipEdit</tabstop>
@@ -215,39 +397,8 @@
   <tabstop>phoneEdit</tabstop>
   <tabstop>notesEdit</tabstop>
  </tabstops>
- <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>EditSupplier</receiver>
-   <slot>onOKButtonClicked()</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>
-   <receiver>EditSupplier</receiver>
-   <slot>onCancelButtonClicked()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>316</x>
-     <y>260</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>286</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <resources>
+  <include location="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"/>
+ </resources>
+ <connections/>
 </ui>

mercurial