Browse Source

存储指标体系。

Ulricy 1 year ago
parent
commit
454b51969c
2 changed files with 46 additions and 0 deletions
  1. 44 0
      QFD/widgets/IndexSystemWidget.cpp
  2. 2 0
      QFD/widgets/IndexSystemWidget.h

+ 44 - 0
QFD/widgets/IndexSystemWidget.cpp

@@ -18,6 +18,8 @@
 #include <QMenu>
 #include <QContextMenuEvent>
 #include <QTabWidget>
+#include <QDir>
+#include <QImageWriter>
 
 #include <QDebug>
 
@@ -108,6 +110,7 @@ void IndexSystemWidget::addNode(CNodeData node)
             m->addNode(node);
         }
     }
+    saveIndexPic();
 }
 
 bool IndexSystemWidget::hasData(QString indexName) const
@@ -134,6 +137,44 @@ bool IndexSystemWidget::hasData(QString indexName) const
     return false;
 }
 
+void IndexSystemWidget::saveIndexPic()
+{
+    if (indexList().size() <= 0 || m_tab->currentIndex() < 0) {
+        return;
+    }
+
+    QString curPath = QDir::currentPath();
+    QString picDir  = curPath + "/index_pics/" + "/";
+    QDir dir(picDir);
+    if (!dir.exists()) {
+        dir.mkpath(picDir);
+    }
+    QString name     = QString("%1_%2").arg(m_proj->id).arg(indexList()[m_tab->currentIndex()]);
+    QString filePath = picDir + name + ".png";
+
+    CMindView *view = (CMindView *)m_tab->currentWidget();
+
+    CMindView *m = new CMindView();
+    m->setNodeList(view->mind()->nodeList());
+
+    int sceneWidth    = m->sceneRect().width();
+    int sceneHeight   = m->sceneRect().height();
+    QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
+    QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
+
+    QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
+    pixmap.fill(QColor(244, 244, 255));
+    QPainter painter(&pixmap);
+    painter.setRenderHints(QPainter::Antialiasing);
+    m->scene()->render(&painter, targetRect, sourceRect);
+    delete m;
+
+    QImageWriter writer(filePath);
+    writer.setFormat("PNG");
+    bool ret = writer.write(pixmap.toImage());
+    qDebug() << __FUNCTION__ << __LINE__ << ret << endl;
+}
+
 void IndexSystemWidget::slotTabCurrentChanged(int c)
 {
     bool ret     = hasData(m_tab->tabText(c));
@@ -188,11 +229,13 @@ void IndexSystemWidget::slotAddSubNode(int pNumber)
 void IndexSystemWidget::slotUpdateNode(CNodeData node)
 {
     CNodeDataService().UpdateCNodeData(node);
+    saveIndexPic();
 }
 
 void IndexSystemWidget::slotRemoveNode(int id)
 {
     CNodeDataService().DeleteCNodeDataById(id);
+    saveIndexPic();
 }
 
 void IndexSystemWidget::slotNodeEdited(CNodeData node)
@@ -203,6 +246,7 @@ void IndexSystemWidget::slotNodeEdited(CNodeData node)
         CMindView *m = (CMindView *)m_tab->currentWidget();
         m->updateNode(node);
     }
+    saveIndexPic();
 }
 
 void IndexSystemWidget::slotImportIndexConfirmed(int projId, int indexType)

+ 2 - 0
QFD/widgets/IndexSystemWidget.h

@@ -36,6 +36,8 @@ private:
 
     bool hasData(QString indexName) const;
 
+    void saveIndexPic();
+
 signals:
 
 public slots: