aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:31:18 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2023-04-30 18:31:18 -0400
commit4de57f628bc74f00ba1885e91c84ea07c5405d8f (patch)
tree5d91900751e826d491ff1b2ebc571a787e84f864 /SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp
parent74d881cefa9097e58e129e37b9c44d680d8c7dfe (diff)
parent3565aad630864ecdbe53fdaa501ea708555b3c7c (diff)
Update upstream source from tag 'upstream/3.4.4+dfsg'
Update to upstream version '3.4.4+dfsg' with Debian dir 482614bd23f0ef52dabc9803477204ad88e917ed
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp
index 41d6ed9..bf8c583 100644
--- a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp
@@ -1,6 +1,8 @@
#include "tablestructuremodel.h"
+#include "datagrid/sqlquerymodelcolumn.h"
#include "iconmanager.h"
#include "common/unused.h"
+#include "parser/ast/sqlitecreatetable.h"
#include <QFont>
#include <QDebug>
#include <QMimeData>
@@ -45,6 +47,9 @@ QVariant TableStructureModel::data(const QModelIndex& index, int role) const
if (createTable->columns.size() <= row)
return QVariant();
+ if (role == Qt::ToolTipRole)
+ return getToolTip(row, getHeaderColumn(index.column()));
+
switch (getHeaderColumn(index.column()))
{
case TableStructureModel::Columns::NAME:
@@ -511,6 +516,98 @@ bool TableStructureModel::isColumnGenerate(SqliteCreateTable::Column* column) co
return false;
}
+QString TableStructureModel::getToolTip(int row, Columns modelColumn) const
+{
+ static const QString tooltipTpl = "<table><tr><td width=16><img src=\"%1\"/></td><td style=\"white-space: pre\"><b>%2</b></td><td>%3</td></tr></table>";
+
+ if (row >= createTable->columns.size())
+ return QString();
+
+ SqliteCreateTable::Column* col = createTable->columns[row];
+ if (col->constraints.isEmpty() && createTable->constraints.isEmpty())
+ return QString();
+
+ SqliteCreateTable::Column::Constraint::Type lookFor;
+ SqliteCreateTable::Constraint::Type lookForTableType;
+ bool tableConstrDefined = false;
+ switch (modelColumn)
+ {
+ case Columns::PK:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::PRIMARY_KEY;
+ lookForTableType = SqliteCreateTable::Constraint::Type::PRIMARY_KEY;
+ tableConstrDefined = true;
+ break;
+ case Columns::FK:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::FOREIGN_KEY;
+ lookForTableType = SqliteCreateTable::Constraint::Type::FOREIGN_KEY;
+ tableConstrDefined = true;
+ break;
+ case Columns::UNIQUE:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::UNIQUE;
+ lookForTableType = SqliteCreateTable::Constraint::Type::UNIQUE;
+ tableConstrDefined = true;
+ break;
+ case Columns::CHECK:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::CHECK;
+ // Not defined for Table-level constraint, because it cannot (easily) determin if it's affected by table CHECK.
+ break;
+ case Columns::NOTNULL:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::NOT_NULL;
+ break;
+ case Columns::COLLATE:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::COLLATE;
+ break;
+ case Columns::GENERATED:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::GENERATED;
+ break;
+ case Columns::DEFAULT:
+ lookFor = SqliteCreateTable::Column::Constraint::Type::DEFAULT;
+ break;
+ case Columns::NAME:
+ case Columns::TYPE:
+ return QString();
+ }
+
+ SqliteCreateTable::Column::Constraint* constraint = findFirst<SqliteCreateTable::Column::Constraint>(
+ col->constraints,
+ [lookFor](SqliteCreateTable::Column::Constraint* constr) -> bool
+ {
+ return constr->type == lookFor;
+ }
+ );
+
+ SqliteCreateTable::Constraint* tableConstraint = nullptr;
+ if (tableConstrDefined)
+ {
+ tableConstraint = findFirst<SqliteCreateTable::Constraint>(
+ createTable->constraints,
+ [lookForTableType](SqliteCreateTable::Constraint* constr) -> bool
+ {
+ return constr->type == lookForTableType;
+ }
+ );
+ }
+
+ if (!constraint && !tableConstraint)
+ return QString();
+
+ if (constraint)
+ {
+ SqlQueryModelColumn::Constraint* constr = SqlQueryModelColumn::Constraint::create(constraint);
+ QString tooltip = tooltipTpl.arg(constr->getIcon()->toUrl(), constr->getTypeString(), constr->getDetails());
+ delete constr;
+ return tooltip;
+ }
+
+ SqlQueryModelColumn::Constraint* constr = SqlQueryModelColumn::Constraint::create(createTable->columns[row]->name, tableConstraint);
+ if (!constr)
+ return QString();
+
+ QString tooltip = tooltipTpl.arg(constr->getIcon()->toUrl(), constr->getTypeString(), constr->getDetails());
+ delete constr;
+ return tooltip;
+}
+
void TableStructureModel::setCreateTable(SqliteCreateTable* value)
{
beginResetModel();