[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/devtools/dbmodeler
From: Hugo Parente Lima <hugo.pl () gmail ! com>
Date: 2006-08-22 20:51:06
Message-ID: 1156279866.584843.17181.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 576019 by hugopl:
Paint table column icons.
M +11 -11 dbmodeler.kdevelop
M +1 -1 model/destroyable.h
M +2 -1 view/diagramscene.cpp
M +69 -17 view/diagramtable.cpp
M +14 -3 view/diagramtable.h
--- trunk/playground/devtools/dbmodeler/dbmodeler.kdevelop #576018:576019
@@ -27,7 +27,7 @@
</ignoreparts>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description></description>
+ <description/>
</general>
<kdevfileview>
<groups>
@@ -83,12 +83,12 @@
</kdevdoctreeview>
<kdevdebugger>
<general>
- <dbgshell></dbgshell>
- <programargs></programargs>
- <gdbpath></gdbpath>
- <configGdbScript></configGdbScript>
- <runShellScript></runShellScript>
- <runGdbScript></runGdbScript>
+ <dbgshell/>
+ <programargs/>
+ <gdbpath/>
+ <configGdbScript/>
+ <runShellScript/>
+ <runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
@@ -102,7 +102,7 @@
<kdevtrollproject>
<run>
<mainprogram>view/view</mainprogram>
- <programargs></programargs>
+ <programargs/>
<directoryradio>build</directoryradio>
<customdirectory>/</customdirectory>
<terminal>false</terminal>
@@ -112,13 +112,13 @@
</envvars>
</run>
<general>
- <activedir>model</activedir>
+ <activedir>tests</activedir>
</general>
<make>
<abortonerror>true</abortonerror>
<numberofjobs>1</numberofjobs>
<dontact>false</dontact>
- <makebin></makebin>
+ <makebin/>
<prio>0</prio>
<envvars/>
<runmultiplejobs>false</runmultiplejobs>
@@ -173,7 +173,7 @@
<headerCompletionDelay>250</headerCompletionDelay>
</codecompletion>
<creategettersetter>
- <prefixGet></prefixGet>
+ <prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
--- trunk/playground/devtools/dbmodeler/model/destroyable.h #576018:576019
@@ -63,11 +63,11 @@
inline void Destroyable::recreate() throw (DiagramException) {
if (!mDestroyed)
return;
+ mDestroyed = false;
recreateMyself();
foreach(Destroyable* item, mDeps)
item->recreate();
mDeps.clear();
- mDestroyed = false;
}
}
--- trunk/playground/devtools/dbmodeler/view/diagramscene.cpp #576018:576019
@@ -73,7 +73,7 @@
DiagramTable* dtable = mTables[table];
Q_ASSERT(dtable);
- dtable->update();
+ dtable->recalc();
RelationMap::iterator i;
foreach(model::Relation* relation, dtable->table()->relations()) {
// when a relation is created, this is slot is created but the
@@ -143,5 +143,6 @@
DiagramTable* dtable = getDiagramTable(static_cast<model::Table*>(item));
Q_ASSERT(dtable);
dtable->setPos(item->position());
+ dtable->updateRelations();
}
}
--- trunk/playground/devtools/dbmodeler/view/diagramtable.cpp #576018:576019
@@ -54,13 +54,8 @@
}
void DiagramTable::recalc() {
- // TODO: This will update the cache.
- update();
-}
-
-QRectF DiagramTable::boundingRect() const {
if (mTable->isDestroyed())
- return QRect();
+ return;
// todo, cache it!
QFont font;
@@ -71,7 +66,7 @@
unsigned int minHeight = ~0;
// table name size
- minWidth = fm.width(mTable->name()) + H_MARGIN*2;
+ minWidth = fm.width(mTable->name()) + H_LEFT_MARGIN + H_RIGHT_MARGIN;
minHeight = fm.height() + V_MARGIN*2;
@@ -79,16 +74,71 @@
int n = mTable->columnCount();
for (int i = 0; i < n; ++i) {
model::Column* col = mTable->column(i);
- minWidth = qMax(fm.width(col->name())+H_MARGIN*2, minWidth );
+ minWidth = qMax(fm.width(col->name())+H_LEFT_MARGIN+H_RIGHT_MARGIN, minWidth );
minHeight += fm.height();
}
- return QRectF(0, 0, minWidth, minHeight);
+ mPixmapCache = QPixmap(minWidth+1, minHeight+1);
+ // draw the table
+ paintTable();
+
+ update();
}
+void DiagramTable::paintTable() {
+ QRectF rect = boundingRect();
+ rect.adjust(0, 0, -1, -1);
+ QFont font;
+ QFontMetrics fm(font); // make font configurable?
+ QPainter painter(&mPixmapCache);
+
+ // background
+ QLinearGradient gradient(0, 0, rect.width(), rect.height());
+ gradient.setColorAt(0, QColor(0xFC, 0xFF, 0xD7));
+ gradient.setColorAt(1, QColor(0xFB, 0xFF, 0x58));
+ painter.fillRect(rect, QBrush(gradient));
+ // table name
+ painter.drawText(0, 0, rect.width(),
+ fm.height()+V_MARGIN*2,
+ Qt::AlignCenter, mTable->name());
+
+ // table columns
+ font.setBold(false);
+ painter.setFont( font );
+ const int N = mTable->columnCount();
+ int v_offset = fm.height()+V_MARGIN*2; // this is the text baseline!
+ QPixmap icon;
+ for (int i = 0; i < N; ++i) {
+ model::Column* col = mTable->column(i);
+ // draw a nice icon =]
+ // todo: otimize this idiot ifelse, we do not need create
+ // and recreate the same pixmap n times.
+ if (col->isPrimaryKey())
+ icon = QPixmap(":/data/pk.png");
+ else if (col->isForeignKey())
+ icon = QPixmap(":/data/fk.png");
+ else
+ icon = QPixmap(":/data/column.png");
+ painter.drawPixmap( H_ICON_MARGIN/2, v_offset, icon);
+
+ // draw text
+ painter.drawText(H_LEFT_MARGIN, v_offset,
+ rect.width()-H_LEFT_MARGIN-H_RIGHT_MARGIN, fm.height(),
+ Qt::AlignVCenter, col->name() );
+ v_offset += fm.height();
+ }
+
+ // draw wires
+ painter.drawRect(rect);
+ v_offset = fm.height()+V_MARGIN;
+ painter.drawLine(0, v_offset, int(rect.width()), v_offset);
+}
+
void DiagramTable::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
+ painter->drawPixmap( 0, 0, mPixmapCache );
+#if 0
if (mTable->isDestroyed())
return;
QFont font;
@@ -135,7 +185,7 @@
painter->setPen(Qt::red);
painter->drawRect(rect);
}
-
+#endif
}
@@ -157,12 +207,7 @@
void DiagramTable::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
// update relations!!!
- const QList<model::Relation*>& relations = mTable->relations();
- foreach(model::Relation* rel, relations) {
- DiagramRelation* drel = mScene->getDiagramRelation(rel);
- if (drel)
- drel->recalc();
- }
+ updateRelations();
QGraphicsItem::mouseMoveEvent(event);
}
@@ -172,6 +217,13 @@
mScene->controller()->editTable(mTable);
}
+void DiagramTable::updateRelations() {
+ const QList<model::Relation*>& relations = mTable->relations();
+ foreach(model::Relation* rel, relations) {
+ DiagramRelation* drel = mScene->getDiagramRelation(rel);
+ if (drel)
+ drel->recalc();
+ }
+}
-
--- trunk/playground/devtools/dbmodeler/view/diagramtable.h #576018:576019
@@ -21,6 +21,7 @@
#define VIEWDIAGRAMTABLE_H
#include <QGraphicsItem>
+#include <QPixmap>
class QGraphicsSceneMouseEvent;
@@ -45,7 +46,9 @@
model::Table* table() const { return mTable; }
void recalc();
- QRectF boundingRect() const;
+ void updateRelations();
+
+ QRectF boundingRect() const { return mPixmapCache.rect(); }
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*);
protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
@@ -56,11 +59,19 @@
private:
DiagramScene* mScene;
model::Table* mTable;
-
+
+ QPixmap mPixmapCache;
+
enum {
- H_MARGIN = 5,
+ ICON_SIZE = 16,
+ H_ICON_MARGIN = 5,
+ H_LEFT_MARGIN = H_ICON_MARGIN+ICON_SIZE,
+ H_RIGHT_MARGIN = 5,
V_MARGIN = 1
};
+
+
+ void paintTable();
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic