Files
sqlitebrowser/src/AddRecordDialog.h
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

53 lines
967 B
C++

#ifndef ADDRECORDDIALOG_H
#define ADDRECORDDIALOG_H
#include "sqlitetypes.h"
#include <QDialog>
class DBBrowserDB;
class QTreeWidgetItem;
namespace Ui {
class AddRecordDialog;
}
class QAbstractButton;
class AddRecordDialog : public QDialog
{
Q_OBJECT
public:
explicit AddRecordDialog(DBBrowserDB& pdb, const sqlb::ObjectIdentifier& tableName, QWidget* parent = nullptr);
~AddRecordDialog();
protected:
void keyPressEvent(QKeyEvent *evt);
private:
enum Columns {
kName = 0,
kType = 1,
kValue = 2,
};
void updateSqlText();
void populateFields();
void setDefaultsStyle(QTreeWidgetItem* item);
private slots:
virtual void accept();
void itemChanged(QTreeWidgetItem* item, int column);
void help();
void on_buttonBox_clicked(QAbstractButton* button);
private:
Ui::AddRecordDialog* ui;
DBBrowserDB& pdb;
sqlb::ObjectIdentifier curTable;
sqlb::Table m_table;
};
#endif