Network model and view
Lingfa Yang
Overview:
- A list node may have one parent one child;
- A tree node may have one parent and more than one child;
- A network node may have more than one parent and more than one child.
Qt provides views for list, tree and table. How about a network model and view?
Network model:
C/C++ developers daily work with plenty of *.h and *.c*. If you pay attention on these #include,
they form an "include-network".
For examples, if you want to extract a group of files, enough and only enough,
to make a library you have to know their dependence;
if you want to remove a file, you have to make sure that it is an orphan,
not been included by any other files in your project. You need a tool to handle it.
Network view:
Diagramming worth a thousand words. Here is my network view.
Fig. 1
A network view example for qtextbrowser.h in Qt\4.3.0\src\gui\widgets (click for fullsize image)
The view is interactive.
-
Hover to display including and included file lists (The color in text is the same as in drawing).
Fig. 2
Hover for toolTip.
-
Click on each node to open the file and edit.
The third party program is used through QProcess.
process->start(program, arguments);
if(process->waitForStarted()); // succeeded
|
-
Window also has drag-resize and scroll bars.
Window is resizable, scrollable, Node is mouse-left and -right clickable.
Code:
File relation in this little project: depend1
Fig. 3
Self-portrait of this little project:depend1.
-
Every application has a main, which creates a MainWindow and show, and holds a event loop.
-
Our MainWindow includes network node model and view.
-
To build the model needs search, and to view the model needs a representative, MyButton.
-
Node has a core.
-
A singleton (SgtMsg) is for general messaging.
-
The core
class NodeCore
{
public:
NodeCore(const QString &name, NodeCore *parent);
protected:
QString name;
QList<NodeCore *> m_parents, m_children;
};
|
- The node with GUI
class IncludeNode : public QObject, NodeCore
|
- The recursive search
search = new IncludeSearch(parents);
int level = 0;
while(!parents.isEmpty())
{
all[level] << parents;
children.clear();
search->nextGeneration(parents, children, prefix);
parents = children;
level ++;
};
|
- The draw
- Catch event to draw
void IncludeNodeView::paintEvent ( QPaintEvent * event )
{
QWidget::paintEvent(event); // system draw
drawLink(); // my draw
}
|
-
Forwarding drawing to them each
void IncludeNodeView::drawLink()
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
for(int i=0; i<col; ++i)
{
for(int j=0; j<all[i].size(); ++j)
{
all[i].at(j)->draw(painter);
}
}
}
|
-
Node itself knows how to draw.
void IncludeNode::draw(QPainter &painter)
{
...
}
|
| Download Win32 exe
| Linux/X11 executable
Dialogs
| Model/View(
List/Tree,
Table, Network)
| XML/
Office 2007 XML
| COM/ActiveX
| Network TCP/IP
| OpenGL
| Online Help ...
|| MyQt
| Qt C++
| C/C++
| eBooks
|