2 #include <QFontMetrics>
4 #include <QGraphicsWidget>
5 #include<QGraphicsSceneContextMenuEvent>
6 #include <QGraphicsItem>
10 #include <QInputDialog>
11 #include "mainwindow.h"
13 #include "association.h"
22 qDebug()<<
"Entite::~Entite()";
43 void Entite::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
45 QGraphicsRectItem::paint(painter,option,0);
48 unLien->QGraphicsItemGroup::update(unLien->
boundingRect());
59 long largeurDuChamp=QFontMetrics(
title->font()).width(
vecteurChamps[noChamp]->getNomComplet())+20;
60 if (largeurDuChamp>largeur) largeur=largeurDuChamp;
63 setRect(0,0,largeur,hauteur);
64 setBrush(QColor(
"#FFFFA4"));
68 rectTitle->setRect(0,0,largeur,QFontMetrics(
title->font()).height()+10);
74 title->setTextWidth(boundingRect().width());
79 if(!association)ordonnee=
rectTitle->rect().height();
80 else ordonnee=
title->boundingRect().height();
85 if(noChamp==0 && !association)
87 texte=
"<b><u>"+
vecteurChamps[noChamp]->getNomComplet()+
"</u></b>";
101 if((leLien->
t1==
this && leLien->
t2==lAutre) ||(leLien->
t2==
this && leLien->
t1==lAutre)){
114 if((leLien->
t1==
this && leLien->
t2==lAutre) ||(leLien->
t2==
this && leLien->
t1==lAutre)){
124 qDebug()<<
"constructeur de table";
138 title->setFont(QFont(
"Verdana",10,QFont::Bold,
false));
141 hauteur+=QFontMetrics(
title->font()).height();
144 for(
int noChamp=0;noChamp<listeDesChamps.count();noChamp++)
146 long largeurDuChamp=QFontMetrics(
title->font()).width(listeDesChamps[noChamp]+
nomEntite);
147 hauteur+=QFontMetrics(
title->font()).height();
148 if (largeurDuChamp>largeurMaxi) largeurMaxi=largeurDuChamp;
152 setRect(x,y,largeurMaxi+10,200);
156 setBrush(QColor(
"#FFFF00"));
158 title->setTextWidth(boundingRect().width());
163 title->setData(32,
"Table");
164 title->setData(34,qVariantFromValue((qlonglong)
this));
167 QGraphicsItem::setData(32,
"Table");
169 QGraphicsItem::setData(34,qVariantFromValue((qlonglong)
this));
170 long ordonne=
title->boundingRect().height();
172 this->setRect(0,0,largeurMaxi+10,ordonne+10);
174 for(
int noChamp=0;noChamp<listeDesChamps.count();noChamp++)
176 QString tipe=
"VARCHAR";
193 vecteurChamps[noChamp]->setData(33,nom+
"."+listeDesChamps[noChamp]);
197 setRect(0,0,largeurMaxi+20,ordonne);
198 setAcceptDrops(
false);
207 qDebug()<<
"void Entite::contextMenuEvent(QGraphicsSceneMouseEvent *event)";
208 QMenu menu(QObject::tr(
"Object Menu"));
211 QAction* titre=
new QAction(menu.title(),this->
maman);
212 titre->setDisabled(
true);
213 menu.addAction(titre);
215 titre->setFont(QFont(
"verdana",9,3,
true));
219 QGraphicsItem::setSelected(
true);
223 QAction *removeAction = menu.addAction(QObject::tr(
"&Remove Object"));
224 QAction *addPropertyAction = menu.addAction(QObject::tr(
"&Add property"));
226 QAction * actionChoisie=menu.exec(event->screenPos());
227 if(actionChoisie==removeAction)
233 if(actionChoisie==addPropertyAction)
244 QVector<Entite*> resultat;
251 resultat.push_back(leLien->
t2);
259 QStringList resultat;
266 if(leLien->
role!=NULL)
275 {
if(leLien->
role!=NULL)
287 QStringList resultat;
289 if(!constraintInsideTable)debut=
"ALTER TABLE "+
nomEntite+
" ADD ";
291 if(!constraintInsideTable)fin=
";";
321 resultat=resultat && (vectEntitesGeneres.contains(leLien->
t2)||leLien->
t1==leLien->
t2);
329 resultat=resultat && vectEntitesGeneres.contains(leLien->
t1);
354 QStringList listeDesNoms;
355 foreach (
Entite* lEntite, entitesMeres)
360 return listeDesNoms.join(
',');
366 QVector<Entite*> vectEnt=((
Association*)
this)->vectEntitesAssociees();
368 foreach (
Entite* lEntite, vectEnt) {
371 return slPK.join(
',');
384 if(!taille.isEmpty()) laChaine+=
"("+taille+
")";
392 QStringList listeDesNoms;
393 foreach (
Entite* lEntite, entitesMeres)
396 listeDesNoms<<laChaine;
404 QVector<Entite*> vectEnt=((
Association*)
this)->vectEntitesAssociees();
406 foreach (
Entite* lEntite, vectEnt) {
409 return slPK.join(
',');
415 QString motReserve=
"#ad2bee";
416 QString typeChamp=
"#87711d";
417 QString nomTable=
"#29a329";
418 QString nomChamp=
"#39b339";
419 QString tailleChamp=
"#97812d";
420 QString laChaine=
"<font color=\""+motReserve+
"\"> foreign key </font> (";
436 qDebug()<<
"QString Entite::toSql()";
440 QString motReserve=
"#ad2bee";
441 QString typeChamp=
"#87711d";
442 QString nomTable=
"#29a329";
443 QString nomChamp=
"#39b339";
444 QString tailleChamp=
"#97812d";
446 resultat=
"<font color=\""+motReserve+
"\">CREATE TABLE</font> <font color=\""+nomTable+
"\">`"+
nomTableTronque()+
"`</font>(";
448 QStringList defChamp;
450 defs<<leChamp->
toSql();
462 defs.append(
"<font color=\""+motReserve+
"\"><b>primary key</b></font>(<u>"+
getPrimaryKey()+
"</u>)");
464 resultat+=defs.join(
',');
Entite * t2
t2 second object
The QCustomGraphicsScene class This class is designed to deal with mouse events.
QString nomEntite
nomEntite name of entity
QString toSql(bool withoutFK=false)
toSql
void selectionne(Entite *lEntite)
selectionne
void tableAjouterChamp(Entite *lEntite, QString nomDuChamp="property name", QString typeDuChamp="Son type", QString roleDuChamp="Son rôle dans l'objet", QString tailleDuChamp="")
tableAjouterChamp
void supprimerLien(Lien *leLien)
supprimerLien
int noLien(Entite *lAutre, Lien *leLien)
noLien
The Lien class a link is betwwen to objects it contains a line a role text cardinality ...
Entite * t1
t1 first object
QVector< Lien * > vectLiens
vectLiens this vector contains adresses of the links concerning entity
QString getPrimaryKey()
getPrimaryKey
QString nomTableTronque()
nomTableTronque
int nbLien(Entite *lAutre)
nbLien
The Association class Association inherit Entite Association is a relation between at least two entit...
QString texteDuRole
texteDuRole example: chief
Entite(MainWindow *mum, QString nom, qreal x, qreal y, QGraphicsItem *parent, QCustomGraphicsScene *laScene, QStringList listeDesChamps, bool isAssoc)
Entite.
QStringList renvoieClefsEtrangeres(bool constraintInsideTable=true)
renvoieClefsEtrangeres
QString typeDeJointure
typeDeJointure cif –1,1–CIF–0,n–> df –0,1–DF–0,n–>or leg --------—
QString getPrimaryKeyAsFields(bool=true)
getPrimaryKeyAsFields
QVector< Property * > vecteurChamps
vecteurChamps container for entity's fields
bool isEntiteFaible()
isEntiteFaible
The Property class property is a field it can be placed into entity or relation.
QStringList renvoieChampsEtrangers()
renvoieChampsEtrangers
QVector< Entite * > renvoieEntiteMeres()
renvoieEntiteMeres
bool canBeWriten(QVector< Entite * > vectEntitesGeneres)
canBeWriten
QGraphicsSimpleTextItem * role
role if there are several links between two same objects
void contextMenuEvent(QGraphicsSceneMouseEvent *event)
contextMenuEvent
void tableSupprimer(Entite *laTableASupprimer, bool demanderConfirmation=true)
tableSupprimer
QString getkeyAsForeignKey(QString role)
getkeyAsForeignKey
The Entite class Entity is an object we have to deal with.
QGraphicsTextItem * title
title
The MainWindow class main code of application.
QRectF boundingRect() const
boundingRect
MainWindow * maman
maman the main window
QGraphicsRectItem * rectTitle
rectTitle rectangle wich contains title