bonjour;
je dois afficher avec Qt4 des sommets et des lignes entre les sommets (un graphe) , je n'ai pas utilisé avant Qt, j'ai trouvé un exemple sur internet mais c'est avec Qt3, j'ai besoin d'aide pour le traduire en Qt4 ou bien de le faire dès le début sur Qt4.
Merci pour vous.

Graphique_Textuelle.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <qcanvas.h>
#include <qpainter.h>
#include "Graphe.h"
#include "sommet.h"
#include "Node.h"
 
/**************************************NOEUD****************************/
class Ellipse_Noeud : public QCanvasEllipse 
{
public:
	Ellipse_Noeud ( int ,int,int,int,int,QCanvas *c ) ;
	Ellipse_Noeud (QCanvas *c) ;
	Node *noeud;
	void drawShape( QPainter &p );
	~Ellipse_Noeud();
	QCanvasText* t;
	int num;
 
};
 
/******************************************ARC**************************/
 
class Line_Arc: public QCanvasLine 
{
public:
	Line_Arc (int,int,int,QCanvas *c ) ;
	void drawShape( QPainter &p );
	~Line_Arc();
	int ndep,narr,val;	
	QCanvasText* t;	
 
};
 
/****************************************GRAPHE**************************/
 
class Canvas_Graphe 
{
public:
	Graphe *gr;
public:
	int min(int a,int b);
	void Bellman(QCanvas *);
	Canvas_Graphe( char*,int i ){gr=new Graphe(i);};
	void addNoeud(Ellipse_Noeud *,int );
	void addArc(Line_Arc*,int );	
	Ellipse_Noeud *tab[30];	
	Line_Arc *arc[30];
	//void drawShape(QPainter *);
	int tv[30];
 
};
Graphique_Textuelle.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "Graphique_Textuelle.h"
#include "Graphe.h"
#include <qstring.h>
#include <stdlib.h>
#include <qpoint.h>
#include <iostream.h>
#include <qcolor.h>
 
/*************************************ARC**************************************************/
Line_Arc ::Line_Arc ( int nd,int arr,int v, QCanvas *c ) : QCanvasLine( c )
{
 
	ndep=nd;
	narr=arr;val=v;
 
};
 
 
Line_Arc ::~Line_Arc()
{
	hide();
};
 
void Line_Arc::drawShape( QPainter &p )
{	
	p.setBrush(QColor(black) );
	p.drawLine(startPoint(),endPoint());
	QPoint p1((startPoint().x()+endPoint().x())/2-10,(startPoint().y()+endPoint().y())/2-10);
	QPoint p2((startPoint().x()+endPoint().x())/2,(startPoint().y()+endPoint().y())/2);
	QPoint p3((startPoint().x()+endPoint().x())/2-10,(startPoint().y()+endPoint().y())/2);
	p.setPen(QColor(white) );
	p.drawText (((startPoint().x()+endPoint().x())/2)+3,((startPoint().y()+endPoint().y())/2)-4,QString::number(val) );
 
	//p.drawLine (p1,p2);
	//p.drawLine (p3,p2);
 
};
/**************************************NOEUD****************************************/
 
 
 
//construct canvasNoeud
Ellipse_Noeud ::Ellipse_Noeud ( int numero,int leng,int larg,int x,int y, QCanvas *c ) : QCanvasEllipse( leng,larg,c )
{
	//noeud
	 noeud =new Node(numero);
	 num=numero;	
};
 
 
void Ellipse_Noeud ::drawShape( QPainter &p )
{
	p.setBrush( QColor("red") );
	p.drawEllipse((int)x()-10,(int)y()-10,40,40);
	p.drawText ((int)x(),(int)y()+5,QString::number(num) );
};
 
Ellipse_Noeud ::~Ellipse_Noeud ()
{
	hide(); // Required to avoid segfault - see docs
};
 
/********************************************GRAPHE***********************************/
 
void Canvas_Graphe::addNoeud(Ellipse_Noeud *cn,int i)
{	
	tab[i]=cn;
 
 
};
 
 
void Canvas_Graphe::addArc(Line_Arc *cl,int i)
{
	int xa,xb,ya,yb;
	for(int j=0;j<i;j++)
	{
		if(tab[j]->noeud->getCN()==cl->ndep)
		{
			tab[j]->noeud->Listesuivant(cl->narr,cl->val);
			//gr->addNode(tab[j]->noeud);
			tab[j]->noeud->afficher();
		}
	}
 
	for(int j=0;j<i;j++)
	{	
		if(tab[j]->noeud->getCN()==cl->ndep)
		{
			 xa=tab[j]->x();
			 ya=tab[j]->y();
			cout<<j<<"--"<<tab[j]->noeud->getCN()<<"---"<<xa<<"-"<<ya<<endl;
		}
	};
 
	for(int j=0;j<i;j++)
	{
		if(tab[j]->noeud->getCN()==cl->narr)
		{
			xb=tab[j]->x();
			yb=tab[j]->y();
			cout<<j<<"--"<<tab[j]->noeud->getCN()<<"---"<<xb<<"-"<<yb<<endl;
		}
	}
	cl->setPoints ( xa, ya,xb,yb );
	cl->setPen( QPen(QColor(150,150,150), 2) );
	cl->setZ(20);
	cl->show();
};
 
 
int Canvas_Graphe::min(int a,int b)
{
	if(a>b) return b;
	return a;
}
 
 
void Canvas_Graphe::Bellman(QCanvas *canvas)
{
	vector<Node>::iterator i;
	list<sommet>::iterator j ;
	int N=gr->tailleGraphe();
	int tc[N],k=0,tva[N],tvs[N],tin[N],tin1[N],id=0,h=0;
 
	//initialisations
	tv[0]=0;
	for(int s=1;s<N;s++)
	tv[s]=1000;
	list<sommet> che;
 
	//calcul du Poid de chaque noeud
	for(i=gr->graphe.begin();i!=gr->graphe.end();i++)
	{	
		tc[k]=i->getCN();
		for(j=i->LesSuivants.begin();j!=i->LesSuivants.end();j++)
		{
			tv[j->GetCS()-1]=min(tv[j->GetCS()-1],tv[k]+j->GetVal());
			//cout<<tv[j->GetCS()-1]<<" "<<j->GetCS()-1<<" "<<k<<endl;
			tvs[h]=tv[j->GetCS()-1];tin[h]=j->GetCS()-1;tin1[h]=k;h++;
		}
		k++;
	}
 
	//recuperation des arcs
	for(i=gr->graphe.begin();i!=gr->graphe.end();i++)
	{	
		for(j=i->LesSuivants.begin();j!=i->LesSuivants.end();j++)
		{
			tva[id++]=j->GetVal();	
		}
	}
 
	list<sommet> ch;
	//insertion
	for(int s=0;s<gr->taille;s++)
	{
		sommet S(tc[s],tv[s]);
		ch.push_back(S);
	}
	gr->afficherGraphe();
	cout<<endl;cout<<endl;
 
	//Affichage en mode textuelle du poid de chaque noeud
	cout<<"Affichage du poids de chaque noeud"<<endl;
	for(j=ch.begin();j!=ch.end();j++)
	{
		cout<<"d(n"<<j->GetCS()<<") = "<<j->GetVal()<<endl;
	}
 
	//Affichage du valeur du chemin minimale
	cout<<endl;
	cout<<"Le chemin le Plus court est de valeur "<<tv[gr->taille-1]<<endl;
	cout<<endl;
 
	//Detection des indices des noeuds qui presentent le chemin minimale 
 
	for(int i=0;i<h;i++)
	{
		tin[i]+=1;tin1[i]+=1;
	}
	bool res=true;
	int d=0;
	int chemin[N];
	chemin[d]=tin[h-1];
	while(res)
	{
		for(int x=0;x<h;x++)
		{
			if(tin[x]==chemin[d])
			{
				cout<<tin[x]<<" "<<x<<endl;
				cout<<tv[tin[x]-1]<<"="<<tva[x]<<"+ "<<tin1[x]<<" "<<tv[tin1[x]-1];
				cout<<endl;
				if(tv[tin[x]-1]==tva[x]+tv[tin1[x]-1])
				{
					d++;
					cout<<d<<endl<<endl;;
					chemin[d]=tin1[x];
				}
			}
		}
		if(chemin[d]==1) res=false;
	}
 
	cout<<endl;
	cout<<endl;
	//Affichage du chemin en mode textuelle
	for(int i=d;i>0;i--)
		cout<<"("<<chemin[i]<<")->";cout<<"("<<chemin[0]<<")";
	cout<<endl;
	//Affichage du chemin en mode graphique
	int mat[d][2];
	int idm=0;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<=d;j++)
		{
			if(chemin[j]==tab[i]->noeud->getCN())
			{
				cout<<chemin[j]<<" "<<tab[i]->x()<<","<<tab[i]->y()<<endl;
				mat[idm][1]=tab[i]->x();mat[idm][2]=tab[i]->y();
				idm++;
			}	
		}
	}
	//coloration du chemin le plus court
	for(int j=0;j<d;j++)
	{
		cout<<j<<mat[j][1]<<" "<<mat[j][2]<<endl;
		QCanvasLine *cl=new QCanvasLine(canvas);
		cl->setPoints ( mat[j][1]+10, mat[j][2]+10,mat[j+1][1]+10,mat[j+1][2]+10 );
		cl->setPen( QPen(QColor(100,100,250),4) );
		cl->setZ(20);
		cl->show();
	}
 
	//destruction du Graphe
	gr->~Graphe();
}
 
/*void Canvas_Graphe::drawShape(QPainter *p)
{
	for(int j=0;j<4;j++)
	{	
		p->drawText (int(tab[j]->x())+2,int(tab[j]->y())+4,QString::number(tv[j]));	
	}
}*/