Files
sqlitebrowser/src/AddRecordDialog.ui
T
Manuel ce032d95e6 Issue #530: constraints on table prevents new record being added (#1477)
* Issue #530: constraints on table prevents new record being added

This adds a new dialog for adding records to a table. The current approach
is broken for several cases where foreign keys and check constraints are
impeding the insertion of an empty record. With the dialog, the user can
inspect the constraints (tooltip) and type of fields and add values
consistent with the requirements. The data is only inserted when the user
presses the Save button.

The dialog is modelled after the Edit Table or Edit Index dialog. An upper
frame allows entering the data using widgets. The lower frame previews the
SQL statement that will be used.

The old approach for adding records is still accessible pressing Tab on
the last cell of the table.

* Fix build problem introduced in previous commit on this branch

* Dialog as fallback for failure after empty row insertion and read only text

The insertion of an empty row is always tried. When it fails due to
constraints and foreign keys, the Add Record Dialog is open so the user
can enter values for the new record considering the constraints.

When the table has not constraints, or the row insertion provides valid
values, the user is still able to insert rows using the simple approach.

SQL preview in dialog is now read-only.

* Visual improvements for the Add Record dialog

QLineEdit as item delegate for the value, so it is more visible that we
are supposed to edit the value.

Remove last end-of-line in tool-tip.

* Improvements in the "Add Record" dialog

Display of NULL values using DisplayRole (no focus) or place holder text
(when focus).

Set value to NULL through a context menu and shortcut in the value line
edit.

Take text type affinity into account for quoting or not entered numbers.
New isType and affinity functions in sqlitetypes.

Clarify wording of constraints in tooltip for value. Added the same tooltip
for the type.

Escape quotes inside string values.

Removed unused parameters warnings.

Other wording or code improvements based on the pull-request review: #1477.

* User access to the Add Record dialog

The Add Record dialog is now accessible for the user. The New Record button
is converted to a QToolButton and a new pop-up menu is added to it for
invoking the in-line table insertion (New Record) or the Add Record dialog
(Insert Values...). What's This information for the button updated.
2018-08-27 21:35:09 +02:00

159 lines
5.4 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddRecordDialog</class>
<widget class="QDialog" name="AddRecordDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>Add New Record</string>
</property>
<property name="windowIcon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/table</normaloff>:/icons/table</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupFields">
<property name="title">
<string>Enter values for the new record considering constraints. Fields in bold are mandatory.</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeWidget" name="treeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>140</height>
</size>
</property>
<property name="whatsThis">
<string>In the Value column you can specify the value for the field identified in the Name column. The Type column indicates the type of the field. Default values are displayed in the same style as NULL values.</string>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
<property name="toolTip">
<string>Values to insert. Pre-filled default values are inserted automatically unless they are changed.</string>
</property>
</column>
</widget>
<widget class="SqlTextEdit" name="sqlTextEdit" native="true">
<property name="whatsThis">
<string>When you edit the values in the upper frame, the SQL query for inserting this new record is shown here. You can edit manually the query before saving.</string>
</property>
<property name="readOnly" stdset="0">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Save&lt;/span&gt; will submit the shown SQL statement to the database for inserting the new record.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Restore Defaults&lt;/span&gt; will restore the initial values in the &lt;span style=&quot; font-weight:600;&quot;&gt;Value&lt;/span&gt; column.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Cancel&lt;/span&gt; will close this dialog without executing the query.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SqlTextEdit</class>
<extends>QWidget</extends>
<header>sqltextedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>treeWidget</tabstop>
<tabstop>sqlTextEdit</tabstop>
</tabstops>
<resources>
<include location="icons/icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>clicked(QAbstractButton*)</signal>
<receiver>AddRecordDialog</receiver>
<slot>on_buttonBox_clicked(QAbstractButton*)</slot>
<hints>
<hint type="sourcelabel">
<x>324</x>
<y>477</y>
</hint>
<hint type="destinationlabel">
<x>324</x>
<y>249</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>itemChanged()</slot>
</slots>
</ui>