288 lines
8.9 KiB
C++
288 lines
8.9 KiB
C++
|
|
#include "preqtablewidget.h"
|
|||
|
|
#include <QMouseEvent>
|
|||
|
|
#include <QDebug>
|
|||
|
|
#include <QApplication>
|
|||
|
|
#include <QMimeData>
|
|||
|
|
#include <QDrag>
|
|||
|
|
#include <QWidget>
|
|||
|
|
|
|||
|
|
#include "CallManage.h"
|
|||
|
|
#include "PropertyWidget.h"
|
|||
|
|
|
|||
|
|
//针对曲线
|
|||
|
|
PreQTableWidget::PreQTableWidget(QWidget *parent) :
|
|||
|
|
QTableWidget(parent)
|
|||
|
|
{
|
|||
|
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
|||
|
|
setAcceptDrops(true);
|
|||
|
|
|
|||
|
|
connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(ChangedItem()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::mousePressEvent(QMouseEvent *event)
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget mousePressEvent";
|
|||
|
|
|
|||
|
|
if (event->button() == Qt::LeftButton)
|
|||
|
|
{
|
|||
|
|
startPos = event->pos();
|
|||
|
|
m_press = true;
|
|||
|
|
}
|
|||
|
|
QTableWidget::mousePressEvent(event);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::ChangedItem()
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget itemSelectionChanged!";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::mouseMoveEvent(QMouseEvent *event)
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget mouseMoveEvent";
|
|||
|
|
|
|||
|
|
if (event->buttons() & Qt::LeftButton)
|
|||
|
|
{
|
|||
|
|
int distance = (event->pos() - startPos).manhattanLength();
|
|||
|
|
if (distance >= QApplication::startDragDistance())
|
|||
|
|
{
|
|||
|
|
performDrag();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
QTableWidget::mouseMoveEvent(event);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::dragEnterEvent(QDragEnterEvent *event)
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget dragEnterEvent";
|
|||
|
|
|
|||
|
|
PreQTableWidget *source = qobject_cast<PreQTableWidget *>(event->source());
|
|||
|
|
if (source && source != this) {
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QMyTreeWidget *sourceTree = qobject_cast<QMyTreeWidget *>(event->source());
|
|||
|
|
if (sourceTree) {
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::dragMoveEvent(QDragMoveEvent *event)
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget dragMoveEvent";
|
|||
|
|
|
|||
|
|
PreQTableWidget *source = qobject_cast<PreQTableWidget *>(event->source());
|
|||
|
|
if (source && source != this) {
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QMyTreeWidget *sourceTree = qobject_cast<QMyTreeWidget *>(event->source());
|
|||
|
|
if (sourceTree) {
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::dropEvent(QDropEvent *event)
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget dropEvent";
|
|||
|
|
|
|||
|
|
PreQTableWidget *source = qobject_cast<PreQTableWidget *>(event->source());
|
|||
|
|
if (source && source != this) {
|
|||
|
|
|
|||
|
|
QString strExtern = event->mimeData()->text();
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QStringList list = strExtern.split("#@@#");//QString字符串分割函数
|
|||
|
|
if (list.size() > 2)
|
|||
|
|
{
|
|||
|
|
QString strSlfName = list[0];
|
|||
|
|
QString strWellName = list[1];
|
|||
|
|
QString strLineName = list[2];
|
|||
|
|
|
|||
|
|
qDebug() << "source strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName;
|
|||
|
|
|
|||
|
|
if(m_strWellName == strWellName)
|
|||
|
|
{
|
|||
|
|
m_AddSuc = true;
|
|||
|
|
//新建曲线
|
|||
|
|
emit CallManage::getInstance()->sig_AddLine(strSlfName, strWellName, m_strTrackName, strLineName);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
//m_listLineName.push_back(strLineName);
|
|||
|
|
|
|||
|
|
// 接受拖拽事件
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// 如果井名不正确,不接受拖拽事件
|
|||
|
|
event->ignore();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
int rownum = rowCount();
|
|||
|
|
setRowCount(rownum+1);
|
|||
|
|
//
|
|||
|
|
QTableWidgetItem* item = new QTableWidgetItem(strExtern);
|
|||
|
|
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
|
|||
|
|
item->setTextAlignment(Qt::AlignCenter); //设置文本居中
|
|||
|
|
//
|
|||
|
|
setItem(rownum, 0, item);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QMyTreeWidget *sourceTree = qobject_cast<QMyTreeWidget *>(event->source());
|
|||
|
|
if (sourceTree) {
|
|||
|
|
|
|||
|
|
QString strExtern = event->mimeData()->text();
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QStringList list = strExtern.split("#@@#");//QString字符串分割函数
|
|||
|
|
if (list.size() > 2)
|
|||
|
|
{
|
|||
|
|
QString strSlfName = list[0];
|
|||
|
|
QString strWellName = list[1];
|
|||
|
|
QString strLineName = list[2];
|
|||
|
|
|
|||
|
|
qDebug() << "sourceTree strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName;
|
|||
|
|
|
|||
|
|
if(m_strWellName == strWellName)
|
|||
|
|
{
|
|||
|
|
m_AddSuc = true;
|
|||
|
|
//新建曲线
|
|||
|
|
emit CallManage::getInstance()->sig_AddLine(strSlfName, strWellName, m_strTrackName, strLineName);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
//m_listLineName.push_back(strLineName);
|
|||
|
|
|
|||
|
|
// 接受拖拽事件
|
|||
|
|
event->setDropAction(Qt::MoveAction);
|
|||
|
|
event->accept();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// 如果井名不正确,不接受拖拽事件
|
|||
|
|
event->ignore();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PreQTableWidget::performDrag()
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget performDrag!";
|
|||
|
|
|
|||
|
|
int iCurrentRow = currentRow();
|
|||
|
|
if( cellWidget(iCurrentRow, 0) != nullptr )
|
|||
|
|
{
|
|||
|
|
auto myWidget = cellWidget(currentRow(), 0);
|
|||
|
|
|
|||
|
|
FormInfo *formInfo = (FormInfo*)myWidget;//获得widget
|
|||
|
|
|
|||
|
|
//曲线对象(AC、BS...)
|
|||
|
|
QMimeData *mimeData = new QMimeData;
|
|||
|
|
// 这里需要根据你的item数据来设置mimeData,例如:
|
|||
|
|
mimeData->setText(formInfo->m_strSlfName + "#@@#"+ formInfo->m_strWellName + "#@@#" +formInfo->m_strLineName);
|
|||
|
|
// 创建QDrag对象
|
|||
|
|
QDrag *drag = new QDrag(this);
|
|||
|
|
drag->setMimeData(mimeData);
|
|||
|
|
// 可以设置拖拽时的光标图标
|
|||
|
|
QRect itemRect = visualItemRect(currentItem()); // 获取项的矩形区域
|
|||
|
|
QPixmap itemPixmap = QWidget::grab(itemRect);//QPixmap::grabWidget(this, itemRect); // 获取项的屏幕截图
|
|||
|
|
// 调整拖拽光标的热点,使其位于截图的中心
|
|||
|
|
drag->setPixmap(itemPixmap);
|
|||
|
|
|
|||
|
|
// 执行拖拽操作
|
|||
|
|
m_AddSuc = false;
|
|||
|
|
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
|||
|
|
if (dropAction == Qt::MoveAction) { //&& m_AddSuc
|
|||
|
|
// 处理拖拽结束的逻辑,例如从界面上移除拖拽的项
|
|||
|
|
removeRow(iCurrentRow);
|
|||
|
|
//删除曲线
|
|||
|
|
emit CallManage::getInstance()->sig_delLine(formInfo->m_strWellName, formInfo->m_strTrackName, formInfo->m_strLineName);
|
|||
|
|
//
|
|||
|
|
//m_listLineName.removeOne(formInfo->m_strLineName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// if(!currentItem())
|
|||
|
|
// {
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// QString strExtern = currentItem()->text();
|
|||
|
|
|
|||
|
|
// QMimeData *mimeData = new QMimeData;
|
|||
|
|
// mimeData->setText(strExtern);
|
|||
|
|
|
|||
|
|
// QDrag *drag = new QDrag(this);
|
|||
|
|
// drag->setMimeData(mimeData);
|
|||
|
|
// if (drag->exec(Qt::MoveAction) == Qt::MoveAction){
|
|||
|
|
// qDebug()<<"Success!";
|
|||
|
|
// }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void PreQTableWidget::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
|
{
|
|||
|
|
if(m_press)//如果鼠标左键被释放
|
|||
|
|
{
|
|||
|
|
qDebug()<<"PreQTableWidget mouseReleaseEvent";
|
|||
|
|
|
|||
|
|
m_press = false;//按下标志置fasle,形成互斥
|
|||
|
|
|
|||
|
|
int iCurrentRow = currentRow();
|
|||
|
|
qDebug()<<"PreQTableWidget mouseReleaseEvent, iCurrentRow=" << QString::number(iCurrentRow);
|
|||
|
|
if( cellWidget(iCurrentRow, 0) != nullptr )
|
|||
|
|
{
|
|||
|
|
auto myWidget = cellWidget(currentRow(), 0);
|
|||
|
|
|
|||
|
|
FormInfo *formInfo = (FormInfo*)myWidget;//获得widget
|
|||
|
|
//
|
|||
|
|
QList<float> listMin;
|
|||
|
|
QList<float> listMax;
|
|||
|
|
QStringList strListOtherLine = getListLineName(formInfo->m_strLineName, listMin, listMax);
|
|||
|
|
//PropertyService()->initCurveProperty(formInfo->m_strSlfName, formInfo->m_strWellName, formInfo->m_strTrackName, formInfo->m_strLineName, formInfo->m_lineColor, formInfo->m_dWidth, strListOtherLine);
|
|||
|
|
|
|||
|
|
PropertyService()->initCurveProperty(formInfo, strListOtherLine, listMin, listMax);
|
|||
|
|
|
|||
|
|
//曲线置顶显示,激活可选
|
|||
|
|
emit CallManage::getInstance()->sig_Raise(formInfo->m_strSlfName, formInfo->m_strWellName, formInfo->m_strTrackName, formInfo->m_strLineName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QStringList PreQTableWidget::getListLineName(QString strLineName, QList<float> &listMin, QList<float> &listMax)
|
|||
|
|
{
|
|||
|
|
QStringList strListOtherLine;
|
|||
|
|
for(int i=0; i<rowCount(); i++)
|
|||
|
|
{
|
|||
|
|
if( cellWidget(i, 0) != nullptr )
|
|||
|
|
{
|
|||
|
|
auto myWidget = cellWidget(i, 0);
|
|||
|
|
|
|||
|
|
FormInfo *formInfo = (FormInfo*)myWidget;//获得widget
|
|||
|
|
QString strTmp = formInfo->m_strLineName;
|
|||
|
|
if(strTmp!=strLineName)
|
|||
|
|
{
|
|||
|
|
strListOtherLine.push_back(strTmp);
|
|||
|
|
listMin.push_back(formInfo->m_vmin);
|
|||
|
|
listMax.push_back(formInfo->m_vmax);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return strListOtherLine;
|
|||
|
|
}
|