Skip to content

Commit b6c5024

Browse files
committed
Data Browser: use font style to indicate keys
- Primary keys are underlined - Foreign keys are italic See issue #2902
1 parent 3a4d7d8 commit b6c5024

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/sqlitetablemodel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static QString toSuperScript(T number)
205205

206206
QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation, int role) const
207207
{
208-
if (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::DecorationRole)
208+
if (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::FontRole)
209209
return QVariant();
210210

211211
if (orientation == Qt::Horizontal)
@@ -218,16 +218,22 @@ QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation,
218218
switch (role) {
219219
case Qt::EditRole:
220220
return QString::fromStdString(plainHeader);
221-
case Qt::DecorationRole: {
222-
bool is_key = false;
221+
case Qt::FontRole: {
222+
bool is_pk = false;
223+
bool is_fk = getForeignKeyClause(column-1).isSet();
224+
223225
if (contains(m_query.rowIdColumns(), m_headers.at(column))) {
224-
is_key = true;
226+
is_pk = true;
225227
} else if (m_table_of_query) {
226228
auto field = sqlb::findField(m_table_of_query, m_headers.at(column));
227229
const auto pk = m_table_of_query->primaryKey();
228-
is_key = pk && contains(pk->columnList(), field->name());
230+
is_pk = pk && contains(pk->columnList(), field->name());
229231
}
230-
return is_key ? QImage(":/icons/field_key") : QVariant();
232+
233+
QFont font;
234+
font.setUnderline(is_pk);
235+
font.setItalic(is_fk);
236+
return font;
231237
}
232238
default:
233239
QString sortIndicator;

0 commit comments

Comments
 (0)