Improve CrudModel code quality
This commit is contained in:
parent
82cc9f14bc
commit
550049ceff
6 changed files with 870 additions and 205 deletions
|
|
@ -9,7 +9,11 @@
|
|||
#include "crud/DataGridWidget.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDeadlineTimer>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "catalog/PgClassContainer.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include <QUrl>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
|
@ -41,6 +45,26 @@ protected:
|
|||
model->setResult(db, result);
|
||||
}
|
||||
|
||||
/// Shows a whole table (CRUD mode) and waits for the asynchronous load to finish
|
||||
bool showTable(const QString &name)
|
||||
{
|
||||
db = openDb();
|
||||
auto table = db->catalog()->classes()->findIf([&name](const PgClass &c)
|
||||
{ return c.fullyQualifiedQuotedObjectName().endsWith("." + name); });
|
||||
if (!table)
|
||||
return false;
|
||||
model = std::make_unique<CrudModel>();
|
||||
widget = std::make_unique<DataGridWidget>();
|
||||
widget->setSourceModel(model.get());
|
||||
bool reset = false;
|
||||
QObject::connect(model.get(), &QAbstractItemModel::modelReset, model.get(), [&reset] { reset = true; });
|
||||
model->setConfig(db, *table);
|
||||
QDeadlineTimer deadline(10000);
|
||||
while (!reset && !deadline.hasExpired())
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
|
||||
return reset;
|
||||
}
|
||||
|
||||
/// Editable flag of every result column, as seen through the widget's proxy
|
||||
std::vector<bool> editableColumns()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue