summaryrefslogtreecommitdiff
path: root/src/items/database/databasetable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/items/database/databasetable.cpp')
-rw-r--r--src/items/database/databasetable.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/items/database/databasetable.cpp b/src/items/database/databasetable.cpp
index a1f83c1..a987984 100644
--- a/src/items/database/databasetable.cpp
+++ b/src/items/database/databasetable.cpp
@@ -15,6 +15,7 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <QGraphicsScene>
+#include <QStringList>
#include <QMimeData>
#include <QDebug>
#include "databasetable.h"
@@ -89,17 +90,20 @@ DatabaseTable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
// Draw the table name
QPointF colPos = m_firstColPos;
QPointF leftSizePos = colPos - QPointF(m_leftSideWidth, 0);
+ int i = 0;
foreach (Column *column, m_columnList->columns()) {
- painter->setFont(column->isRequired()
+ bool isBold = column->isRequired();
+ painter->setFont(isBold
? (column->isPrimaryKey() ? boldFontWithUnderline : boldFont)
: font);
painter->drawText(colPos, column->name());
- if (column->isPrimaryKey()) {
- painter->setFont(column->isRequired() ? boldFont : font);
- painter->drawText(leftSizePos, "PK");
+ if (!m_columnLabels[i].isEmpty()) {
+ painter->setFont(isBold ? boldFont : font);
+ painter->drawText(leftSizePos, m_columnLabels[i]);
}
colPos += m_colPosIncrement;
leftSizePos += m_colPosIncrement;
+ ++i;
}
// Draw the outside border
@@ -166,17 +170,25 @@ DatabaseTable::updateLayout()
qreal width = nameWidth + spaceWidth * 2;
qreal maxColumnWidth = 0;
+ m_columnLabels.clear();
foreach (Column *column, m_columnList->columns()) {
qreal columnWidth = column->isRequired() ? boldFontMetrics.width(column->name()) : fontMetrics.width(column->name());
maxColumnWidth = qMax(maxColumnWidth, columnWidth);
qreal columnLeftSideWidth = 0;
+ QStringList label;
if (column->isPrimaryKey()) {
- if (column->isRequired()) {
- columnLeftSideWidth = boldFontMetrics.width("PK");
- }
- else {
- columnLeftSideWidth = fontMetrics.width("PK");
- }
+ label << "PK";
+ }
+ if (column->isForeignKey()) {
+ label << "FK";
+ }
+ QString labelStr = label.join(",");
+ m_columnLabels << labelStr;
+ if (column->isRequired()) {
+ columnLeftSideWidth = boldFontMetrics.width(labelStr);
+ }
+ else {
+ columnLeftSideWidth = fontMetrics.width(labelStr);
}
m_leftSideWidth = qMax(m_leftSideWidth, columnLeftSideWidth);
}