调整UI显示层级逻辑

master
bob.pan 5 years ago
parent d77755f952
commit c0c4ef5782

@ -19,7 +19,7 @@ class IDetectorUI
{ {
public: public:
virtual bool Initialize(IDetectorEngine* lpDE) = 0; virtual bool Initialize(IDetectorEngine* lpDE) = 0;
virtual bool ShowMainFrame() = 0; virtual bool ShowMainFrame(class QWidget* parent = nullptr) = 0;
}; };

@ -1871,7 +1871,7 @@ void ImageCompareModelInvoker::operator()(const cv::Range& range) const
{ {
int i0 = range.start; int i0 = range.start;
int i1 = range.end; int i1 = range.end;
assert(abs(i1 - i0) == 1); //assert(abs(i1 - i0) == 1);
//if (abs(i1 - i0) == 1) //if (abs(i1 - i0) == 1)
// return; // return;
m_pModel->parallelDetect(i0, m_pData); m_pModel->parallelDetect(i0, m_pData);

@ -28,7 +28,7 @@ bool CDetectorUI::Initialize(IDetectorEngine* lpDE)
return true; return true;
} }
bool CDetectorUI::ShowMainFrame() bool CDetectorUI::ShowMainFrame(class QWidget* parent)
{ {
if (!m_pMainFrame->Initialize(m_pDE)) if (!m_pMainFrame->Initialize(m_pDE))
return false; return false;
@ -36,6 +36,12 @@ bool CDetectorUI::ShowMainFrame()
if (!m_pMainFrame->InitGraphView()) if (!m_pMainFrame->InitGraphView())
return false; return false;
m_pMainFrame->setParent(parent);
m_pMainFrame->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pMainFrame->setWindowIcon(QIcon(":/image/leaper"));
m_pMainFrame->setWindowModality(Qt::ApplicationModal);
m_pMainFrame->setAttribute(Qt::WA_ShowModal, true);
m_pMainFrame->show(); m_pMainFrame->show();
return true; return true;
} }

@ -9,7 +9,7 @@ public:
CDetectorUI(); CDetectorUI();
virtual ~CDetectorUI(); virtual ~CDetectorUI();
bool Initialize(IDetectorEngine* lpDE); bool Initialize(IDetectorEngine* lpDE);
virtual bool ShowMainFrame(); virtual bool ShowMainFrame(class QWidget* parent = nullptr);
private: private:
CMainFrame* m_pMainFrame{ nullptr }; CMainFrame* m_pMainFrame{ nullptr };
IDetectorEngine* m_pDE{ nullptr }; IDetectorEngine* m_pDE{ nullptr };

@ -1,13 +1,9 @@
#include "RoiImgViewer.h" #include "RoiImgViewer.h"
#include <QDebug> #include <QDebug>
//#include "qtUtils.h"
#include <algorithm> #include <algorithm>
#include <QDateTime> #include <QDateTime>
RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/)
//#define DEBUG_PRINT
RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/)
: lpImgViewer(parent) : lpImgViewer(parent)
, mMouseCaptureStatus(MouseCaptureNone) , mMouseCaptureStatus(MouseCaptureNone)
, mDrawStatus(DrawNone) , mDrawStatus(DrawNone)
@ -15,12 +11,12 @@
, mpDrawingLineItem(NULL) , mpDrawingLineItem(NULL)
, mpDrawingRectItem(NULL) , mpDrawingRectItem(NULL)
, mpSelectedRoiNode(NULL) , mpSelectedRoiNode(NULL)
{ {
connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode()));
} }
QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img)
{ {
if (lpImgViewer::setImg(img)) if (lpImgViewer::setImg(img))
{ {
mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false);
@ -30,10 +26,10 @@
{ {
return NULL; return NULL;
} }
} }
QGraphicsItem* RoiImgViewer::firstSelectedItem() QGraphicsItem* RoiImgViewer::firstSelectedItem()
{ {
auto selectedItemList = scene()->selectedItems(); auto selectedItemList = scene()->selectedItems();
if (selectedItemList.size()) if (selectedItemList.size())
{ {
@ -43,10 +39,10 @@
{ {
return NULL; return NULL;
} }
} }
void RoiImgViewer::setDrawStatus(DrawStatus s) void RoiImgViewer::setDrawStatus(DrawStatus s)
{ {
mDrawStatus = s; mDrawStatus = s;
// if(mpImgItem){ // if(mpImgItem){
@ -59,10 +55,10 @@
// printf("RoiImgViewer::setDrawStatus false\n"); // printf("RoiImgViewer::setDrawStatus false\n");
// } // }
// } // }
} }
void RoiImgViewer::clearRois(int type /*= -1*/) void RoiImgViewer::clearRois(int type /*= -1*/)
{ {
QGraphicsScene* pScene = scene(); QGraphicsScene* pScene = scene();
if (type < 0) if (type < 0)
{ {
@ -97,10 +93,10 @@
} }
rejectDrawingItem(); rejectDrawingItem();
} }
void RoiImgViewer::clearExistRois() void RoiImgViewer::clearExistRois()
{ {
QGraphicsScene* pScene = scene(); QGraphicsScene* pScene = scene();
foreach(auto itemList, mRoiItemMap) foreach(auto itemList, mRoiItemMap)
@ -114,10 +110,10 @@
mRoiItemMap.clear(); mRoiItemMap.clear();
mRoiNodeList.clear(); mRoiNodeList.clear();
mpSelectedRoiNode = NULL; mpSelectedRoiNode = NULL;
} }
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/)
{ {
DrawStatus backupDrawStatus = mDrawStatus; DrawStatus backupDrawStatus = mDrawStatus;
QString backupChannelName = getChannel(); QString backupChannelName = getChannel();
@ -142,10 +138,10 @@
mDrawStatus = backupDrawStatus; mDrawStatus = backupDrawStatus;
setChannel(backupChannelName); setChannel(backupChannelName);
} }
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id)
{ {
setDrawStatus(DrawRect); setDrawStatus(DrawRect);
// QPolygonF qrect = mapToScene(rect.toRect()); // QPolygonF qrect = mapToScene(rect.toRect());
// mDrawingRect = qrect.boundingRect(); // mDrawingRect = qrect.boundingRect();
@ -155,10 +151,10 @@
//setFixedSizeScale(scale); //setFixedSizeScale(scale);
acceptDrawingItem(); acceptDrawingItem();
lastRectRoi()->id = id; lastRectRoi()->id = id;
} }
void RoiImgViewer::addRoiLine(QLineF line, QString id) void RoiImgViewer::addRoiLine(QLineF line, QString id)
{ {
setDrawStatus(DrawLine); setDrawStatus(DrawLine);
mDrawingLine = line; mDrawingLine = line;
createDrawingItem(); createDrawingItem();
@ -166,10 +162,10 @@
acceptDrawingItem(); acceptDrawingItem();
//lastRectRoi()->id = id; //lastRectRoi()->id = id;
setDrawStatus(DrawNone); setDrawStatus(DrawNone);
} }
LP_ROI_NODE* RoiImgViewer::lastRectRoi() LP_ROI_NODE* RoiImgViewer::lastRectRoi()
{ {
if (mRoiNodeList.size()) if (mRoiNodeList.size())
{ {
return &mRoiNodeList.last(); return &mRoiNodeList.last();
@ -178,10 +174,10 @@
{ {
return NULL; return NULL;
} }
} }
void RoiImgViewer::mousePressEvent(QMouseEvent *event) void RoiImgViewer::mousePressEvent(QMouseEvent *event)
{ {
QGraphicsItem* pItem = firstSelectedItem(); QGraphicsItem* pItem = firstSelectedItem();
if (!pItem) if (!pItem)
{ {
@ -257,10 +253,10 @@
} }
lpImgViewer::mousePressEvent(event); lpImgViewer::mousePressEvent(event);
} }
void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt)
{ {
lpImgViewer::mouseMoveEvent(evt); lpImgViewer::mouseMoveEvent(evt);
QGraphicsItem* pItem = dynamic_cast<QGraphicsItem*>( QGraphicsItem* pItem = dynamic_cast<QGraphicsItem*>(
@ -356,10 +352,10 @@
} }
} }
} }
void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
mMouseCaptureStatus = MouseCaptureNone; mMouseCaptureStatus = MouseCaptureNone;
@ -406,10 +402,10 @@
} }
} }
lpImgViewer::mouseReleaseEvent(event); lpImgViewer::mouseReleaseEvent(event);
} }
void RoiImgViewer::wheelEvent(QWheelEvent *evt) void RoiImgViewer::wheelEvent(QWheelEvent *evt)
{ {
lpImgViewer::wheelEvent(evt); lpImgViewer::wheelEvent(evt);
if (!mpSelectedRoiNode) if (!mpSelectedRoiNode)
@ -418,10 +414,10 @@
} }
mpSelectedRoiNode->fScale = mFixedSizeScale; mpSelectedRoiNode->fScale = mFixedSizeScale;
} }
void RoiImgViewer::keyPressEvent(QKeyEvent *event) void RoiImgViewer::keyPressEvent(QKeyEvent *event)
{ {
if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) {
QGraphicsScene* pScene = scene(); QGraphicsScene* pScene = scene();
@ -451,15 +447,15 @@
} }
} }
} }
} }
QRectF extRect(const QRectF& r, float w) QRectF extRect(const QRectF& r, float w)
{ {
return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w);
} }
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/)
{ {
MouseCaptureStatus ret = MouseCaptureNone; MouseCaptureStatus ret = MouseCaptureNone;
QRectF validRect = extRect(r, capDis); QRectF validRect = extRect(r, capDis);
@ -486,15 +482,15 @@
} }
return ret; return ret;
} }
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/)
{ {
return MouseCaptureNone; return MouseCaptureNone;
} }
void RoiImgViewer::updateSelectedRoiNode() void RoiImgViewer::updateSelectedRoiNode()
{ {
QGraphicsItem* pItem = firstSelectedItem(); QGraphicsItem* pItem = firstSelectedItem();
LP_ROI_NODE *pRoiNode = findRoiNode(pItem); LP_ROI_NODE *pRoiNode = findRoiNode(pItem);
@ -503,10 +499,10 @@
mpSelectedRoiNode = pRoiNode; mpSelectedRoiNode = pRoiNode;
emit roiSelectionChanged(mpSelectedRoiNode); emit roiSelectionChanged(mpSelectedRoiNode);
} }
} }
void RoiImgViewer::updateDrawingItem() void RoiImgViewer::updateDrawingItem()
{ {
switch (mDrawStatus) switch (mDrawStatus)
{ {
case DrawLine: case DrawLine:
@ -540,10 +536,10 @@
default: default:
break; break;
} }
} }
void RoiImgViewer::createDrawingItem() void RoiImgViewer::createDrawingItem()
{ {
switch (mDrawStatus) switch (mDrawStatus)
{ {
case DrawLine: case DrawLine:
@ -571,10 +567,10 @@
default: default:
break; break;
} }
} }
void RoiImgViewer::acceptDrawingItem() void RoiImgViewer::acceptDrawingItem()
{ {
//clearExistRois(); //clearExistRois();
switch (mDrawStatus) switch (mDrawStatus)
{ {
@ -595,10 +591,10 @@
default: default:
break; break;
} }
} }
void RoiImgViewer::rejectDrawingItem() void RoiImgViewer::rejectDrawingItem()
{ {
switch (mDrawStatus) switch (mDrawStatus)
{ {
case DrawLine: case DrawLine:
@ -612,16 +608,16 @@
default: default:
break; break;
} }
} }
void RoiImgViewer::resetAllDrawingItems() void RoiImgViewer::resetAllDrawingItems()
{ {
mpDrawingLineItem = NULL; mpDrawingLineItem = NULL;
mpDrawingRectItem = NULL; mpDrawingRectItem = NULL;
} }
void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem)
{ {
int type = pItem->type(); int type = pItem->type();
if (mRoiItemMap.contains(type)) if (mRoiItemMap.contains(type))
{ {
@ -649,10 +645,10 @@
mRoiNodeList.append(roi_node); mRoiNodeList.append(roi_node);
} }
} }
LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem)
{ {
auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode)
{ {
return roiNode.pItem == pItem; return roiNode.pItem == pItem;
@ -665,6 +661,6 @@
{ {
return &(*i); return &(*i);
} }
} }

@ -5,8 +5,6 @@
#include <iostream> #include <iostream>
#include <QtDebug> #include <QtDebug>
lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/) lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/)
: QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01), : QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01),
mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false)
@ -25,16 +23,11 @@ lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/)
setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
} }
void lpImgViewer::setInitScale(qreal val) void lpImgViewer::setInitScale(qreal val)
{ {
scaleImg2(val); scaleImg2(val);
} }
QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img)
{ {
if (mpImg) if (mpImg)
@ -50,8 +43,6 @@ QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img)
mImgOriSize = img.size(); mImgOriSize = img.size();
mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height()); mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height());
//qreal scale = std::min((qreal)size().width() / img.width(), (qreal)size().height() / img.height());
if (isAutoResetTransform()) if (isAutoResetTransform())
{ {
mpImgItem->setPos(0, 0); mpImgItem->setPos(0, 0);

@ -191,13 +191,9 @@ lpMainWin::lpMainWin(QWidget *parent)
//当某个模板加入训练或者不加入训练时修改原来工作单中的模板信息 //当某个模板加入训练或者不加入训练时修改原来工作单中的模板信息
connect(m_pModelMgrDlg, SIGNAL(sgModifyModel(QString)), this, SLOT(modWorkMgr(QString))); connect(m_pModelMgrDlg, SIGNAL(sgModifyModel(QString)), this, SLOT(modWorkMgr(QString)));
connect(m_pModelMgrDlg, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect())); connect(m_pModelMgrDlg, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect()));
/*
void sgAddNewModel(QString strName);//添加模板 connect(m_pModelMgrDlg, SIGNAL(sgAddNewModel(QString)), this, SLOT(onSlotAddNewModel(QString)));//新建模板型号
void sgDelOldModel(QString strName);//删除模板 connect(m_pModelMgrDlg, SIGNAL(sgDelOldModel(QString)), this, SLOT(onSlotDelOldModel(QString)));//删除模板型号
void sgModeModeName(QString strOld, QString strNew);//修改模板名
*/
connect(m_pModelMgrDlg, SIGNAL(sgAddNewModel(QString)), this, SLOT(onSlotAddNewModel(QString)));
connect(m_pModelMgrDlg, SIGNAL(sgDelOldModel(QString)), this, SLOT(onSlotDelOldModel(QString)));
@ -1050,7 +1046,7 @@ Q_SLOT void lpMainWin::onActionClicked()
} }
else if ("action_designer" == strObj) { else if ("action_designer" == strObj) {
if (m_pDesigner) { if (m_pDesigner) {
m_pDesigner->ShowMainFrame(); m_pDesigner->ShowMainFrame(this);
} }
} }
} }

Loading…
Cancel
Save