1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava software.
4 // \file canMainWindow.cpp
5 // \author Benoit Autheman (benoit@libqanava.org)
6 // \date 2005 November 11
7 //-----------------------------------------------------------------------------
11 #include "../../src/qanRepository.h"
12 #include "../../src/qanGraphItemModel.h"
13 #include "../../src/qanGraphItemView.h"
14 #include "../../src/qanGrid.h"
15 #include "../../src/qanTreeLayout.h"
16 #include "./mainWindow.h"
22 #include <QHeaderView>
23 #include <QTextCursor>
25 #include <QToolButton>
30 void generateBranch( Graph
& _graph
, Node
& superNode
, int depth
, QProgressDialog
* progress
, QApplication
* app
, bool root
= false )
35 int subNodeCount
= 1 + ( rand( ) % 4 );
36 app
->processEvents( );
38 progress
->setMaximum( subNodeCount
);
40 for ( int n
= 0; n
< subNodeCount
; n
++ )
44 app
->processEvents( );
45 progress
->setValue( n
);
46 if ( progress
->wasCanceled( ) )
52 label
+= QString::number( _graph
.getNodeCount( ) );
53 Node
* node
= _graph
.addNode( label
);
54 _graph
.addEdge( superNode
, *node
);
56 bool goDeeper
= ( rand( ) % 3 );
58 generateBranch( _graph
, *node
, depth
, progress
, app
);
62 void generateTree( Graph
& _graph
, QProgressDialog
* progress
, QApplication
* app
, int depth
= 5 )
64 Node
* root
= _graph
.addNode( "Root" );
66 generateBranch( _graph
, *root
, depth
, progress
, app
, true );
69 //-----------------------------------------------------------------------------
70 MainWindow::MainWindow( QApplication
* application
, QWidget
* parent
) :
71 QMainWindow( parent
),
72 _application( application
)
76 QHBoxLayout
*hboxA
= new QHBoxLayout( _frameA
);
77 hboxA
->setMargin( 0 );
78 QHBoxLayout
*hboxB
= new QHBoxLayout( _frameB
);
79 hboxB
->setMargin( 0 );
81 // Create a graph item view and generate a simple graph
82 Graph
* graph
= new Graph( );
83 _graphItemViewA
= new qan::GraphItemView( _frameA
, graph
, QColor( 255, 255, 255 ) );
84 GridItem
* grid
= new GridCheckBoardItem( _graphItemViewA
->getGraphicsView( ), palette( ).color( QPalette::Base
), palette( ).color( QPalette::AlternateBase
) );
86 _graphItemViewB
= new qan::GraphItemView( _frameB
, graph
, QColor( 255, 255, 255 ) );
87 new GridCheckBoardItem( _graphItemViewB
->getGraphicsView( ), palette( ).color( QPalette::Base
), palette( ).color( QPalette::AlternateBase
) );
89 QProgressDialog
* progress
= new QProgressDialog( "Generating graph...", "Cancel", 0, 100, this );
90 progress
->setWindowModality( Qt::WindowModal
);
92 generateTree( *graph
, progress
, _application
, 4 );
95 hboxA
->addWidget( _graphItemViewA
);
96 _graphItemViewA
->setModel( graph
);
97 _graphItemViewA
->layoutGraph( );
99 hboxB
->addWidget( _graphItemViewB
);
100 _graphItemViewB
->setModel( graph
);
101 _graphItemViewB
->layoutGraph( );
104 _graphItemViewA
->setGraphLayout( new qan::HierarchyTree( QPointF( 120., 55. ), QPointF( 10., 10. ), Qt::Horizontal
) );
105 _graphItemViewA
->layoutGraph( );
107 _graphItemViewB
->setGraphLayout( new qan::ChanTree( ) );
108 _graphItemViewB
->layoutGraph( );
110 //-----------------------------------------------------------------------------