调整UI显示层级逻辑

master
bob.pan 5 years ago
parent d77755f952
commit c0c4ef5782

@ -19,7 +19,7 @@ class IDetectorUI
{
public:
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 i1 = range.end;
assert(abs(i1 - i0) == 1);
//assert(abs(i1 - i0) == 1);
//if (abs(i1 - i0) == 1)
// return;
m_pModel->parallelDetect(i0, m_pData);

@ -28,7 +28,7 @@ bool CDetectorUI::Initialize(IDetectorEngine* lpDE)
return true;
}
bool CDetectorUI::ShowMainFrame()
bool CDetectorUI::ShowMainFrame(class QWidget* parent)
{
if (!m_pMainFrame->Initialize(m_pDE))
return false;
@ -36,6 +36,12 @@ bool CDetectorUI::ShowMainFrame()
if (!m_pMainFrame->InitGraphView())
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();
return true;
}

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

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

@ -5,8 +5,6 @@
#include <iostream>
#include <QtDebug>
lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/)
: QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01),
mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false)
@ -25,16 +23,11 @@ lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/)
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
}
void lpImgViewer::setInitScale(qreal val)
{
scaleImg2(val);
}
QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img)
{
if (mpImg)
@ -50,8 +43,6 @@ QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img)
mImgOriSize = img.size();
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())
{
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(sgUpdatedefect()), this, SLOT(onUpdateDefect()));
/*
void sgAddNewModel(QString strName);//添加模板
void sgDelOldModel(QString strName);//删除模板
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)));
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) {
if (m_pDesigner) {
m_pDesigner->ShowMainFrame();
m_pDesigner->ShowMainFrame(this);
}
}
}

Loading…
Cancel
Save