diff --git a/pip b/pip index 4910631..d3ffc19 160000 --- a/pip +++ b/pip @@ -1 +1 @@ -Subproject commit 4910631ce8daaf7ef5dad6eae4ce0e1d6b7cb83d +Subproject commit d3ffc19610147b94329cf5013e573d85f493be4a diff --git a/qad/application/lang/qad_application_en.ts b/qad/application/lang/qad_application_en.ts index 824e696..cc85e91 100644 --- a/qad/application/lang/qad_application_en.ts +++ b/qad/application/lang/qad_application_en.ts @@ -118,11 +118,25 @@ + + Clear - + + + Select All + + + + + + Copy + + + + All diff --git a/qad/application/lang/qad_application_ru.ts b/qad/application/lang/qad_application_ru.ts index c4d9101..bb4ba21 100644 --- a/qad/application/lang/qad_application_ru.ts +++ b/qad/application/lang/qad_application_ru.ts @@ -118,11 +118,25 @@ + + Clear Очистить - + + + Select All + Выделить всё + + + + + Copy + Копировать + + + All Все diff --git a/qad/application/logview.cpp b/qad/application/logview.cpp index eb39473..da2a99c 100644 --- a/qad/application/logview.cpp +++ b/qad/application/logview.cpp @@ -28,11 +28,19 @@ void LogView::Category::makeIcon(QSize size, QSize size_icon) { } - - LogView::LogView(QWidget * parent): QWidget(parent) { ui = new Ui::LogView(); ui->setupUi(this); + ui->textEdit->setContextMenuPolicy(Qt::ActionsContextMenu); + actionLogSelectAll = new QAction(QIcon(":/icons/select-all.png"), tr("Select All")); + actionLogCopy = new QAction(QIcon(":/icons/edit-copy.png"), tr("Copy")); + actionLogClear = new QAction(QIcon(":/icons/edit-clear.png"), tr("Clear")); + connect(actionLogSelectAll, SIGNAL(triggered(bool)), ui->textEdit, SLOT(selectAll())); + connect(actionLogCopy, SIGNAL(triggered(bool)), ui->textEdit, SLOT(copy())); + connect(actionLogClear, SIGNAL(triggered(bool)), ui->textEdit, SLOT(clear())); + ui->textEdit->addAction(actionLogSelectAll); + ui->textEdit->addAction(actionLogCopy); + ui->textEdit->addAction(actionLogClear); ui->buttonClear->setDefaultAction(ui->actionClear); ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this)); ui->comboCategory->addItem(tr("All")); @@ -66,53 +74,101 @@ QFont LogView::logFont() const { bool LogView::isFilterVisible() const { - return !ui->widgetToolbar->isHidden(); + return ui->widgetToolbar->isVisible(); } int LogView::linesLimit() const { - return ui->textEdit->document()->maximumBlockCount(); + int ret = ui->textEdit->document()->maximumBlockCount(); + if (ret > 0) --ret; + return ret; } void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QColor color, bool bold) { - if (keyword.isEmpty()) keyword = label; - if (keyword.isEmpty()) return; - Category & c(categories[keyword]); + QRegularExpression regexp(keyword, QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)); + registerCategory(label, regexp, icon, color, bold); +} + + +void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QColor color, bool bold) { + if (!regexp.isValid() || regexp.pattern().isEmpty()) return; + removeCategory(regexp); + Category c; + c.regexp = regexp; c.label = label; - c.keyword = keyword; c.image = icon; c.color = color; c.bold = bold; c.makeIcon(iconImageSize(), preferredIconSize(1., this)); - ui->comboCategory->addItem(c.icon, label, keyword); + categories.append(c); + ui->comboCategory->addItem(c.icon, label, QVariant(regexp)); +} + + +void LogView::removeCategory(QString keyword) { + QRegularExpression regexp(keyword, QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)); + removeCategory(regexp); +} + + +void LogView::removeCategory(QRegularExpression regexp) { + Category c; + c.regexp = regexp; + categories.removeAll(c); + for (int i = 1; i < ui->comboCategory->count(); ++i) { + if (ui->comboCategory->itemData(i).toRegularExpression().pattern() == regexp.pattern()) { + ui->comboCategory->removeItem(i); + --i; + } + } +} + + +void LogView::clearCategories() { + ui->comboCategory->blockSignals(true); + while (ui->comboCategory->count() > 1) + ui->comboCategory->removeItem(ui->comboCategory->count() - 1); + categories.clear(); + ui->comboCategory->blockSignals(false); + filter(); } void LogView::addText(const QString & text, bool insert_newline) { + if (text.isEmpty()) return; QTextCursor tc(ui->textEdit->document()); QStringList sl = text.split("\n"); tc.movePosition(QTextCursor::End); QScrollBar * bar = ui->textEdit->verticalScrollBar(); - bool at_end = (bar->value() == bar->maximum()); + bool at_end = (bar->value() == bar->maximum()) || bar->isHidden(); for (int i = 0; i < sl.size(); ++i) { tc.insertText(sl[i]); if ((i < sl.size() - 1) || insert_newline) newLine(); } if (at_end) - bar->setValue(bar->maximum()); - filter(); + scrollToBottom(); } void LogView::changeEvent(QEvent * e) { - if (e->type() == QEvent::Polish) { + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + ui->comboCategory->setItemText(0, tr("All")); + actionLogSelectAll->setText(tr("Select All")); + actionLogCopy->setText(tr("Copy")); + actionLogClear->setText(tr("Clear")); + break; + case QEvent::Polish: { ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this)); QSize is = iconImageSize(), is_i = preferredIconSize(1., this); - QMutableMapIterator it(categories); - while (it.hasNext()) - it.next().value().makeIcon(is, is_i); + for (int i = 0; i < categories.size(); ++i) + categories[i].makeIcon(is, is_i); + } break; + default: break; } } @@ -123,16 +179,14 @@ void LogView::newLine() { tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); QString line = tc.selectedText(); QImage icon; - QMapIterator it(categories); - while (it.hasNext()) { - it.next(); - if (line.contains(it.key(), Qt::CaseInsensitive)) { + foreach (const Category & c, categories) { + if (line.contains(c.regexp)) { QTextCharFormat cf = def_cf; - cf.setForeground(it.value().color); - if (it.value().bold) + cf.setForeground(c.color); + if (c.bold) cf.setFontWeight(QFont::Bold); tc.setCharFormat(cf); - icon = it.value().icon_image; + icon = c.icon_image; break; } } @@ -140,6 +194,10 @@ void LogView::newLine() { tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor); tc.insertImage(icon); } + QRegularExpression regexp = ui->comboCategory->currentData().toRegularExpression(); + QString fs = ui->lineEdit->text(); + if (isFilterVisible()) + filterBlock(tc.block(), fs, regexp); tc.movePosition(QTextCursor::End); tc.setCharFormat(def_cf); tc.insertBlock(); @@ -152,13 +210,30 @@ QSize LogView::iconImageSize() { } +void LogView::filterBlock(QTextBlock block, const QString & fs, const QRegularExpression & regexp) { + bool vis = true;//, pvis = block.isVisible(); + QString line = block.text(); + if (!line.isEmpty()) { + if (line[0] == QChar::ObjectReplacementCharacter) + line.remove(0, 1); + } + if (regexp.isValid()) vis = vis && line.contains(regexp); + if (!fs.isEmpty()) vis = vis && line.contains(fs, Qt::CaseInsensitive); + block.setVisible(vis); + //qDebug() << "filterBlock" << line << vis; + //if (vis != pvis) + // ;//ui->textEdit->document()->mar +} + + void LogView::setFilterVisible(bool yes) { ui->widgetToolbar->setHidden(!yes); + filter(); } void LogView::setLinesLimit(int l) { - ui->textEdit->document()->setMaximumBlockCount(l); + ui->textEdit->document()->setMaximumBlockCount(l <= 0 ? 0 : l + 1); } @@ -167,17 +242,25 @@ void LogView::clear() { } +void LogView::scrollToBottom() { + QScrollBar * bar = ui->textEdit->verticalScrollBar(); + bar->setValue(bar->maximum()); +} + + void LogView::filter() { QTextDocument * doc = ui->textEdit->document(); int bc = doc->blockCount(); - QString fs[2] = {ui->comboCategory->currentData().toString(), ui->lineEdit->text()}; + QRegularExpression regexp; + QString fs; + if (isFilterVisible()) { + regexp = ui->comboCategory->currentData().toRegularExpression(); + fs = ui->lineEdit->text(); + } QTextBlock bl; for (int i = 0; i < bc; ++i) { bl = doc->findBlockByNumber(i); - bool vis = true; - if (!fs[0].isEmpty()) vis = vis && bl.text().contains(fs[0], Qt::CaseInsensitive); - if (!fs[1].isEmpty()) vis = vis && bl.text().contains(fs[1], Qt::CaseInsensitive); - bl.setVisible(vis); + filterBlock(bl, fs, regexp); } doc->markContentsDirty(0, bl.position() + bl.length()); } diff --git a/qad/application/logview.h b/qad/application/logview.h index 8212056..d0d470b 100644 --- a/qad/application/logview.h +++ b/qad/application/logview.h @@ -23,11 +23,13 @@ #include #include #include -#include #include +#include #include "qad_export.h" class QTextEdit; +class QTextBlock; +class QAction; namespace Ui { class LogView; @@ -56,6 +58,15 @@ public: QColor color = QColor(), bool bold = false); + void registerCategory(const QString & label, + QRegularExpression regexp, + const QImage & icon = QImage(), + QColor color = QColor(), + bool bold = false); + void removeCategory(QString keyword); + void removeCategory(QRegularExpression regexp); + void clearCategories(); + void addText(const QString & text, bool insert_newline = true); private: @@ -63,20 +74,23 @@ private: Category(); void makeIcon(QSize size, QSize size_icon); QString label; - QString keyword; + QRegularExpression regexp; QImage image, icon_image; QIcon icon; QColor color; bool bold; + inline bool operator ==(const Category & it) const {return (regexp.pattern() == it.regexp.pattern());} }; void changeEvent(QEvent * e); void newLine(); QSize iconImageSize(); + void filterBlock(QTextBlock block, const QString & fs, const QRegularExpression & regexp); Ui::LogView * ui; - QMap categories; // by keyword + QList categories; QTextCharFormat def_cf; + QAction * actionLogSelectAll, * actionLogCopy, * actionLogClear; public slots: void setFilterVisible(bool yes); @@ -84,6 +98,7 @@ public slots: void clear(); private slots: + void scrollToBottom(); void filter(); signals: diff --git a/qad/application/logview.ui b/qad/application/logview.ui index 46eba44..e06e155 100644 --- a/qad/application/logview.ui +++ b/qad/application/logview.ui @@ -107,6 +107,12 @@ true + + false + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + diff --git a/qad/application/qad_application.qrc b/qad/application/qad_application.qrc index 794f52d..aed461c 100644 --- a/qad/application/qad_application.qrc +++ b/qad/application/qad_application.qrc @@ -29,5 +29,7 @@ ../icons/layer-visible-on.png ../icons/logview.png ../icons/qt.png + ../icons/select-all.png + ../icons/select-none.png diff --git a/qad/graphic/graphic.cpp b/qad/graphic/graphic.cpp index d8c4d2d..a77636d 100644 --- a/qad/graphic/graphic.cpp +++ b/qad/graphic/graphic.cpp @@ -5,10 +5,11 @@ #include "ui_graphic_conf.h" #include #include -#if QT_VERSION < 0x050000 -# include -# include -# include +#include +#include +#include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) +# include #endif #ifndef Q_OS_ANDROID # define HAS_GL @@ -25,17 +26,6 @@ __GraphicRegistrator__ __graphic_registrator__; Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) { canvas_gl = 0; - QTranslator * trans = new QTranslator(); - trans->load(":/lang/qad_graphic_" + QLocale::system().name().left(2)); - if (trans->isEmpty()) - trans->load("lang/qad_graphic_" + QLocale::system().name().left(2)); -#if QT_VERSION >= 0x050000 - if (!qApp->installTranslator(trans)) - delete trans; -#else - qApp->installTranslator(trans); -#endif - fullscr_dialog = 0; gesture_angle = 45.; leg_update = true; visible_update = fullscr = need_mouse_pan = false; @@ -47,10 +37,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), #endif ui = new Ui::Graphic(); ui->setupUi(this); - /*line_x_min.resize(70, 22); - line_x_max.resize(70, 22); - line_y_min.resize(70, 22); - line_y_max.resize(70, 22);*/ line_x_min.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); line_x_max.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); ((QBoxLayout * )ui->widgetLY->layout())->insertWidget(0, &line_y_min); @@ -59,8 +45,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), ((QBoxLayout * )ui->widgetLX->layout())->addWidget(&line_x_max); tm.restart(); grid_numbers_x = grid_numbers_y = 1; - LN2 = qLn(2.); - LN5 = qLn(5.); LN10 = qLn(10.); line_x_min.setClearButtonVisible(true); line_x_max.setClearButtonVisible(true); @@ -84,10 +68,9 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), icon_exp_sy = QIcon(":/icons/expand_s_y.png"); icon_pause_b = QImage(":/icons/pause-back.png"); icon_pause_f = QImage(":/icons/pause-front.png"); - aupdate = grid = isFit = isEmpty = navigation = true; - aalias = mupdate = bufferActive = isOGL = cancel = isPrinting = guides = hasLblX = hasLblY = isHover = false; + aupdate = grid = isFit = navigation = true; + aalias = bufferActive = isOGL = cancel = guides = hasLblX = hasLblY = isHover = false; pause_ = only_expand_x = only_expand_y = false; - //qDebug() << -DBL_MAX/2. << DBL_MAX/2. << DBL_MIN; limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX); eminx = eminy = DBL_MAX; emaxx = emaxy = DBL_MIN; @@ -95,13 +78,9 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), axis_type_x = Numeric; min_repaint_int = 25; inc_x = 1.; - legy = 0; buffer = 0; gridx = gridy = 1.; history = 5.; - min_int = 1; - max_int = 200; - mdm = 10.; visible_time = -1.; thick = lineThickness(); pause_phase = 0.; @@ -113,8 +92,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), selbrush.setColor(QColor(60, 175, 255, 100)); text_color = palette().color(QPalette::WindowText); grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine); - //graph_pen = QPen(Qt::red); - //graph_pen.setCosmetic(true); graphics.append(GraphicType()); curGraphic = 0; selpen = palette().color(QPalette::WindowText); @@ -162,7 +139,6 @@ void Graphic::timerEvent(QTimerEvent * ) { bool Graphic::eventFilter(QObject * o, QEvent * e) { - //qDebug() << "event" << o << e; if (o == canvas) { switch (e->type()) { case QEvent::Gesture: @@ -192,25 +168,7 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) { } break; default: break; } - } /*else { - if (fullscr) { - switch (e->type()) { - case QEvent::KeyPress: - if ((((QKeyEvent*)e)->key() != Qt::Key_Back) || !fullscr) - break; - case QEvent::Close: - leaveFullscreen(); - return true; - case QEvent::OrientationChange: - case QEvent::Resize: { - QWidget * rw = canvas->parentWidget(); - if (rw) - canvas->setGeometry(0, 0, rw->width(), rw->height()); - } break; - default: break; - } - } - }*/ + } return QFrame::eventFilter(o, e); } @@ -223,7 +181,6 @@ void Graphic::prepareCanvas(QWidget * w) { connect(w, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * ))); connect(w, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * ))); connect(w, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * ))); - //w->grabGesture(Qt::TapGesture); w->grabGesture(Qt::TapAndHoldGesture); w->grabGesture(Qt::PanGesture); w->grabGesture(Qt::PinchGesture); @@ -246,7 +203,6 @@ void Graphic::procGesture(QGesture * g) { } break; case Qt::PinchGesture: { QPinchGesture * pg = (QPinchGesture*)g; - //qDebug() << pg->totalRotationAngle(); Qt::KeyboardModifiers km = Qt::NoModifier; if (gesture_angle <= 20.) km = Qt::ControlModifier; if (gesture_angle >= 70.) km = Qt::ShiftModifier; @@ -261,10 +217,8 @@ void Graphic::procGesture(QGesture * g) { QMetaObject::invokeMethod(this, "enterFullscreen", Qt::QueuedConnection); } break; default: - qDebug() << g; break; } - //qDebug() << g; } @@ -295,8 +249,6 @@ void Graphic::totalUpdate() { void Graphic::canvasPaintEvent() { if (is_lines_update) return; - //QMutexLocker ml(&mutex_); - //static int pwid = 0, phei = 0; int wid = canvas->width(), hei = canvas->height(); if (canvas->isHidden() || wid <= 1 || hei <= 1) return; lastw = wid; @@ -320,19 +272,6 @@ void Graphic::canvasPaintEvent() { drawGuides(); return; } - //if (!aupdate && !mupdate && pwid == wid && phei == hei) return; - /*if (pwid != wid || phei != hei) { - line_x_min.move(0, hei - 35); - line_x_max.move(0, 0); - line_y_min.move(70, hei - line_x_min.height()); - line_y_max.move(wid - line_y_max.width(), hei - line_x_min.height()); - } - line_x_min.setVisible(grid); - line_x_max.setVisible(grid); - line_y_min.setVisible(grid); - line_y_max.setVisible(grid);*/ - //pwid = wid; - //phei = hei; QPainter p; #ifdef HAS_GL if (isOGL) { @@ -364,7 +303,6 @@ void Graphic::canvasPaintEvent() { else glDisable(GL_MULTISAMPLE); } #endif - //p.setRenderHint(QPainter::HighQualityAntialiasing, aalias); fp_size.clear(); if (!aalias) p.translate(-0.5, -0.5); drawGraphics(); @@ -418,7 +356,7 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) { case gaMove: dp = e->pos() - prevpos; dp.rx() *= selrect.width() / double(gridborder.x() + 5 - lastw); - dp.ry() *= selrect.height() / double(lasth - legy - gridborder.y() - 5); + dp.ry() *= selrect.height() / double(lasth - gridborder.y() - 5); if (e->modifiers() == Qt::ControlModifier) dp.setY(0.); if (e->modifiers() == Qt::ShiftModifier) @@ -533,11 +471,18 @@ void Graphic::canvasMouseDoubleClickEvent(QMouseEvent * ) { void Graphic::canvasWheelEvent(QWheelEvent * e) { - //if (curaction != gaMove) return; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + emit graphicWheelEvent(canvas2real(e->position()), e->delta()/* TODO: test use angleDelta()*/); +#else emit graphicWheelEvent(canvas2real(QPointF(e->pos())), e->delta()); +#endif if (gestures) return; if (!navigation) return; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + procZoom(e->position(), e->delta(), e->modifiers()); +#else procZoom(e->pos(), e->delta(), e->modifiers()); +#endif totalUpdate(); } @@ -577,7 +522,6 @@ void Graphic::canvasKeyPressEvent(QKeyEvent * e) { void Graphic::clear() { - //cout << "clear" << endl; for (int i = 0; i < graphics.size(); ++i) { graphics[i].polyline.clear(); graphics[i].polyline_pause.clear(); @@ -591,9 +535,6 @@ void Graphic::clear() { void Graphic::setAntialiasing(bool enabled) { if (aalias == enabled) return; aalias = enabled; - /*QGLFormat f = canvas_gl->format(); - f.setSampleBuffers(enabled); - canvas_gl->setFormat(f);*/ update(); } @@ -630,7 +571,6 @@ void Graphic::setHistorySize(double val) { x = pol.back().x() - history; for (int j = pol.size() - 2; j >= 0 ; --j) if (pol[j].x() < x) { - //qDebug() << pol.size() << j; pol.erase(pol.begin(), pol.begin() + j); break; } @@ -747,8 +687,6 @@ void Graphic::addPoint(const QPointF & p, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0) return; GraphicType & t(graphics[graphic]); if (!t.cvrect.isNull() && !pause_) { -// if (graphics[graphic].cvrect.contains(p)) -// graphics[graphic].cvrect = QRectF(); if (t.cvrect.top() < p.y()) t.cvrect.setTop(p.y()); if (t.cvrect.bottom() > p.y()) t.cvrect.setBottom(p.y()); if (t.cvrect.right() < p.x()) t.cvrect.setRight(p.x()); @@ -815,9 +753,7 @@ void Graphic::saveImage() { if (str == "") return; ppath = str; QPixmap im(canvas->size()); - mupdate = true; canvas->render(&im); - mupdate = false; im.save(ppath); update(true); } @@ -840,29 +776,24 @@ void Graphic::setOpenGL(bool on) { ui->canvas_raster->show(); canvas = ui->canvas_raster; #endif - /*line_x_min.setParent(canvas); - line_x_max.setParent(canvas); - line_y_min.setParent(canvas); - line_y_max.setParent(canvas); - line_x_min.show(); - line_x_max.show(); - line_y_min.show(); - line_y_max.show();*/ update(); } void Graphic::update(bool force) { - mupdate = true; repaintCanvas(force); - mupdate = false; } void Graphic::setGraphicsCount(int arg, bool update) { if (arg < 0) return; - while (graphics.size() < arg) + while (graphics.size() < arg) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + graphics.append(GraphicType(tr("y(x)"), QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - QRandomGenerator::global()->generate() % 115))); +#else graphics.append(GraphicType(tr("y(x)"), QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - qrand() % 115))); +#endif + } while (graphics.size() > arg) { delete graphics.back().pb; graphics.pop_back(); @@ -879,76 +810,11 @@ void Graphic::removeGraphic(int arg, bool update) { } -/*void Graphic::setHistogramData(const QVector & g, int graphic) { - graphics[graphic].polyline.clear(); - if (g.isEmpty()) { - return; - } - QVector data = g; - QVector hist; - int ic = max_int, ci; - double md, cd, min, max, range, cx; - qSort(data); - md = DBL_MAX; - min = max = data[0]; - for (int i = 1; i < data.size(); ++i) { - if (min > data[i]) min = data[i]; - if (max < data[i]) max = data[i]; - cd = qAbs(data[i] - data[i - 1]); - if (md > cd && cd != 0.) md = cd; - } - range = max - min; - md = mdm; - //qDebug() << md << range << ic; - if (md != 0.) - ic = qRound(qMax(qMin(double(ic), range / md), double(min_int))); - md = range / ic; - hist.resize(ic); - foreach (const float & i, data) { - ci = qRound((i - min) / range * double(ic - 1)); - //if (ci < 0) ci = 0; - //if (ci >= ic) ci = ic - 1; - hist[ci]++; - } - QPolygonF & cpol(graphics[graphic].polyline); - if (hist.size() == 1 || range == 0.) { - cpol << QPointF(min - 0.5, 0.) << QPointF(min - 0.25, 0.); - cpol << QPointF(min - 0.25, hist[0]) << QPointF(min + 0.25, hist[0]); - cpol << QPointF(min + 0.25, 0.) << QPointF(min + 0.5, 0.); - } else { - cpol << QPointF(min, 0.); - for (int i = 0; i < hist.size(); ++i) { - cx = i * range / ic + min; - cpol << QPointF(cx, hist[i]) << QPointF(cx + md, hist[i]); - } - cpol << QPointF(range + min, 0.); - } - updateGraphics(); -}*/ - - void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, double end_y) { double cx, cy, maxX, minX, maxY, minY, vx; bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y); -// bool isEmpty = true; - //bool fast = true; bool can_fast = (start_x == 0 && end_x == 0 && start_y == 0 && end_y == 0); bool anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY); - //bool force_find = (visible_time > 0.) && (history > 0.) && (visible_time < history); - //if (force_find) can_fast = false; -// foreach (const GraphicType & t, graphics) { -// const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); -// if (!pol.isEmpty()) { -// isEmpty = false; -// break; -// } -// } -// if (isEmpty) { -// grect = def_rect; -// setRectToLines(); -// return; -// } -// can_fast = false; vx = -DBL_MAX; minY = minX = DBL_MAX; maxY = maxX = -DBL_MAX; @@ -957,14 +823,12 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou if (vx < (pause_ ? t.max_x_pause : t.max_x)) vx = (pause_ ? t.max_x_pause : t.max_x); } vx -= visible_time; - //qDebug() << "[Graphic]" << "can_fast" << can_fast; for (int g = 0; g < graphics.size(); g++) { GraphicType & t(graphics[g]); if (!t.visible) continue; const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); if (pol.isEmpty()) continue; bool f = true; - //qDebug() << "[Graphic]" << "cvrect:" << t.cvrect << t.cvrect.isNull(); if (t.cvrect.isNull() || !can_fast) { for (int i = 0; i < pol.size(); i++) { cx = pol[i].x(); @@ -981,10 +845,8 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou if (t.cvrect.right() < cx) t.cvrect.setRight(cx); if (t.cvrect.left() > cx) t.cvrect.setLeft(cx); } - //fast = false; } if (f) continue; - //qDebug() << "[Graphic]" << "2 cvrect:" << t.cvrect; } anyVisible = true; if (maxY < t.cvrect.top()) maxY = t.cvrect.top(); @@ -994,13 +856,10 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou if (!can_fast) t.cvrect = QRectF(); } if (!anyVisible) { - //qDebug() << "[Graphic]" << "empty autofit"; grect = def_rect; setRectToLines(); return; } -// if (fast) qDebug() << "[Graphic]" << "FAST autofit"; -// else qDebug() << "[Graphic]" << "autofit"; if (maxX > limit_.right()) maxX = limit_.right(); if (minX > limit_.right()) minX = limit_.right(); if (minX < limit_.left()) minX = limit_.left(); @@ -1027,7 +886,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou else if (isRangeY) selrect.setRect(minX, start_y, maxX - minX, end_y - start_y); else grect.setRect(minX, minY, maxX - minX, maxY - minY); grect = grect.normalized(); - if (isFit)/* || isRangeX || isRangeY)*/ { + if (isFit) { if (visible_time > 0.) { if (grect.width() > visible_time) grect.setLeft(grect.right() - visible_time); @@ -1039,7 +898,6 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou void Graphic::drawAction() { - //qDebug() << "draw action"; int wid = canvas->width(), hei = canvas->height() - gridborder.y(), sx = startpos.x(), sy = startpos.y(), cx = curpos.x(), cy = curpos.y(); painter->setPen(selpen); painter->setBrush(selbrush); @@ -1067,7 +925,7 @@ void Graphic::drawAction() { void Graphic::drawGrid() { - int gbx = gridborder.x(), gby = gridborder.y(), cwid = canvas->width(), chei = canvas->height() - legy; + int gbx = gridborder.x(), gby = gridborder.y(), cwid = canvas->width(), chei = canvas->height(); double px, py, range, step, start; int wid = cwid - gbx - 5, hei = chei - gby - 5, cx, cy, cnt; QRect rect; @@ -1075,7 +933,7 @@ void Graphic::drawGrid() { range = selrect.bottom() - selrect.top(); if (grad_y == Graphic::Auto) step = splitRange(range, hei / gridy / font_sz.height() / 1.4); - else step = gridy;//range / hei * gridy; + else step = gridy; start = roundTo(canvas2realY(-hei), step) - step; py = start + step; cy = 0; @@ -1132,7 +990,7 @@ void Graphic::drawGrid() { QString df; if (axis_type_x == Graphic::Numeric) { if (grad_x == Graphic::Auto) step = splitRange(range, wid / gridx / font_sz.width() * 1.4); - else step = gridx;//range / wid * gridx; + else step = gridx; start = roundTo(canvas2realX(wid), step) + step; px = start + step; if (step > 0.) { @@ -1172,21 +1030,15 @@ void Graphic::drawGrid() { start = roundTo(canvas2realX(wid), step) + step; px = start + step; QDateTime cd = QDateTime::fromMSecsSinceEpoch(px * grid_numbers_x); - //qDebug() << "*** start" << cd << step; roundDateTime(cd, cur_scl); - //qDebug() << "*** round" << cd; addDateTime(cd, cur_scl); - //qDebug() << "*** add" << cd; - //qDebug() << "*** cur" << cur_scl[0] << cur_scl[1] << cur_scl[2] << cur_scl[3] << cur_scl[4] << cur_scl[5] << cur_scl[6]; if (step > 0.) { cnt = 1000; while (cnt-- > 0) { addDateTime(cd, cur_scl, -1); - //roundDateTime(cd, cur_scl); - //qDebug() << "next" << cd; cx = real2canvasX(cd.toMSecsSinceEpoch() / grid_numbers_x); if (cx > cwid) continue; - if (cx < gbx) {/*qDebug() << cx << "<" << gbx;*/ break;} + if (cx < gbx) break; painter->setPen(grid_pen); painter->drawLine(cx, hei + 5, cx, 0); painter->setPen(text_color); @@ -1230,13 +1082,12 @@ void Graphic::drawGraphics() { if (isHover) ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos)))); QPointF srp = -selrect.topLeft(); - double sclx, scly, wid = canvas->width(), hei = canvas->height() - legy; + double sclx, scly, wid = canvas->width(), hei = canvas->height(); sclx = (wid - gridborder.x() - margins_.left() - margins_.width()) / selrect.width(); scly = (hei - gridborder.y() - margins_.top() - margins_.height()) / selrect.height(); painter->setClipping(true); painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y())); painter->translate(gridborder.x() + margins_.left(), hei - gridborder.y() - margins_.top()); - //if (isOGL && aalias) pen.setWidthF(1.5f); painter->scale(sclx, -scly); painter->translate(srp); QTransform mat = painter->transform(); @@ -1257,8 +1108,6 @@ void Graphic::drawGraphics() { if (t.fill) { cpol = rpol; painter->setBrush(t.fill_color); - //cpol.push_front(QPointF(cpol.front().x(), 0.)); - //cpol.push_back(QPointF(cpol.back().x(), 0.)); painter->drawPolygon(mat.map(cpol)); } else painter->drawPolyline(mat.map(rpol)); @@ -1350,7 +1199,6 @@ double Graphic::splitRange(double range, int count) { double Graphic::splitRangeDate(double range, int count, QString * format, int step[7]) { double ret = splitRange(range, count); - //qDebug() << "ret =" << ret << getScaleX(); if (ret < 1000. * 1) {*format = "ss.zzz"; step[0] = ret;} else if (ret < 1000. * 60) {*format = "h:m:ss"; step[1] = qRound(ret / 1000);} else if (ret < 1000. * 60 * 60) {*format = "h:mm"; step[2] = qRound(ret / 1000 / 60);} @@ -1370,7 +1218,6 @@ double Graphic::roundTo(double value, double round_to) { void Graphic::roundDateTime(QDateTime & dt, int c[7]) { QDate d(dt.date()); QTime t(dt.time()); - //if (c[0] != 0) t.setHMS(t.hour(), t.minute(), t.second(), 0); if (c[1] != 0) t.setHMS(t.hour(), t.minute(), t.second()); if (c[2] != 0) t.setHMS(t.hour(), t.minute(), 0); if (c[3] != 0) t.setHMS(t.hour(), 0, 0); @@ -1400,7 +1247,7 @@ double Graphic::canvas2realX(double px) const { double Graphic::canvas2realY(double py) const { - int gby = gridborder.y() + margins_.top(), chei = lasth - legy, hei = chei - gby - margins_.height(); + int gby = gridborder.y() + margins_.top(), chei = lasth, hei = chei - gby - margins_.height(); double cy = chei - py - gby, scly = selrect.height() / (double)hei; return cy * scly + selrect.y(); } @@ -1414,7 +1261,7 @@ double Graphic::real2canvasX(double px) const { double Graphic::real2canvasY(double py) const { - int gby = gridborder.y() + margins_.top(), chei = lasth - legy, hei = chei - gby - margins_.height(); + int gby = gridborder.y() + margins_.top(), chei = lasth, hei = chei - gby - margins_.height(); double scly = selrect.height() / (double)hei; return chei - gby - (py - selrect.y()) / scly; } @@ -1469,7 +1316,6 @@ void Graphic::setCanvasCursor(QCursor cursor) { void Graphic::swapToBuffer() { QImage timg; - //qDebug() << "render start"; #ifdef HAS_GL if (isOGL) { timg = canvas_gl->grabFrameBuffer(); @@ -1478,16 +1324,12 @@ void Graphic::swapToBuffer() { p.end(); } #endif - //qDebug() << "render finish"; bufferActive = true; } void Graphic::setRectToLines() { is_lines_update = true; - //line_x_min.is_auto = line_x_max.is_auto = line_y_min.is_auto = line_y_max.is_auto = true; - //qDebug() << "set to lines" << selrect; - //line_x_min.is_reset = line_x_max.is_reset = line_y_min.is_reset = line_y_max.is_reset = isFit; if (line_x_min.isVisible() && line_x_max.isVisible() && line_y_min.isVisible() && line_y_max.isVisible()) { line_x_min.blockSignals(true); line_x_max.blockSignals(true); line_y_min.blockSignals(true); line_y_max.blockSignals(true); if (!line_x_min.hasFocus()) { @@ -1511,12 +1353,7 @@ void Graphic::setRectToLines() { line_y_min.setDefaultText(QString::number(grect.bottom()).toUpper()); line_y_max.setDefaultText(QString::number(grect.top()).toUpper()); line_x_min.blockSignals(false); line_x_max.blockSignals(false); line_y_min.blockSignals(false); line_y_max.blockSignals(false); -// if(isFit) { -// line_y_min.setValue(grect.left()); -// line_y_max.setValue(grect.left()); -// } } - //line_x_min.is_auto = line_x_max.is_auto = line_y_min.is_auto = line_y_max.is_auto = false; is_lines_update = false; } @@ -1529,7 +1366,6 @@ void Graphic::checkLines() { void Graphic::tick(int index, bool slide, bool update_) { if (slide) { - ///mutex.lock(); GraphicType & t(graphics[index]); if (history > 0.) while (t.polyline.size() > 1) { @@ -1549,17 +1385,13 @@ void Graphic::tick(int index, bool slide, bool update_) { } if (!update_) { if (isFit) findGraphicsRect(); - ///mutex.unlock(); return; } - //polyline.push_back(QPointF(brick->time_, brick->output(port))); - //cout << polyline.size() << endl; if (isFit) findGraphicsRect(); if (!slide) { if (aupdate) update(); return; } - ///mutex.unlock(); if (aupdate) update(); } @@ -1650,10 +1482,8 @@ void Graphic::updateLegend(bool es) { } if (!ui->widgetLegend->isVisibleTo(this)) { if (es) emit graphicSettingsChanged(); -// qDebug() << "skip updateLegend"; return; } -// qDebug() << "updateLegend" << graphics.size(); leg_update = false; int ps = 100; for (int r = 0; r < ui->layoutLegend->rowCount(); ++r) @@ -1669,12 +1499,10 @@ void Graphic::updateLegend(bool es) { for (int i = 0; i < graphics.size(); i++) { graphics[i].pb = new QCheckBox(graphics[i].name); graphics[i].pb->setIconSize(pix.size()); - //graphics[i].pb->setFlat(true); graphics[i].pb->setIcon(graphics[i].icon); graphics[i].pb->setChecked(graphics[i].visible); graphics[i].pb->setProperty("graphic_num", i); graphics[i].pb->setContextMenuPolicy(Qt::ActionsContextMenu); - //qDebug() << graphics[i].pb->actions(); QAction * act = new QAction(tr("Check all"), 0); act->setCheckable(true); act->setChecked(true); @@ -1719,7 +1547,6 @@ void Graphic::graphicVisibleChange(bool checked) { if (isFit) on_buttonAutofit_clicked(); else update(); emit graphicSettingsChanged(); - //update(); } @@ -1738,7 +1565,6 @@ void Graphic::graphicAllVisibleChange(bool checked) { void Graphic::enterFullscreen() { if (fullscr) return; - //QMessageBox::information(0, "", "enter"); fullscr = true; canvas->hide(); #ifdef Q_OS_ANDROID @@ -1750,7 +1576,6 @@ void Graphic::enterFullscreen() { QPushButton * btn = new QPushButton("Leave fullscreen"); dlg.layout()->addWidget(btn); connect(btn, SIGNAL(clicked(bool)), this, SLOT(leaveFullscreen())); - //connect(fullscr_dialog, SIGNAL(finished(int)), this, SLOT(leaveFullscreen())); canvas->show(); dlg.showFullScreen(); dlg.exec(); @@ -1771,9 +1596,7 @@ void Graphic::leaveFullscreen() { if (tm_fscr.elapsed() < 100) return; #endif if (!fullscr) return; - //QMessageBox::information(0, "", "leave"); fullscr = false; - //canvas->hide(); #ifndef Q_OS_ANDROID canvas->showNormal(); canvas->hide(); @@ -1828,7 +1651,6 @@ QByteArray Graphic::save() { void Graphic::load(QByteArray ba) { if (ba.isEmpty()) return; char ver = ba[0]; - //qDebug() << "load" << (int)ver; switch(ver) { case '2': {// version '2': ba.remove(0, 1); diff --git a/qad/graphic/graphic.h b/qad/graphic/graphic.h index 4976d87..c34bc15 100644 --- a/qad/graphic/graphic.h +++ b/qad/graphic/graphic.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -113,16 +113,12 @@ class QAD_EXPORT Graphic: public QFrame Q_PROPERTY(double graduationStepY READ graduationStepY WRITE setGraduationStepY) Q_PROPERTY(AxisType axisType READ axisType WRITE setAxisType) - Q_PROPERTY(int histogramMinIntervals READ histogramMinIntervals WRITE setHistogramMinIntervals) - Q_PROPERTY(int histogramMaxIntervals READ histogramMaxIntervals WRITE setHistogramMaxIntervals) - Q_PROPERTY(double histogramMinDeltaMultiplier READ histogramMinDeltaMultiplier WRITE setHistogramMinDeltaMultiplier) - Q_PROPERTY(Graphic::GraphicsData graphicsData READ graphicsData WRITE setGraphicsData) Q_PROPERTY(QByteArray graphicsDataRaw READ graphicsDataRaw WRITE setGraphicsDataRaw) public: Graphic(QWidget * parent = 0); - ~Graphic(); + virtual ~Graphic(); typedef QVector > GraphicsData; enum GraphicAction {gaNone, gaZoomInRect, gaZoomRangeX, gaZoomRangeY, gaMove}; @@ -196,9 +192,6 @@ public: QRectF limit() const {return limit_;} QRect margins() const {return margins_;} int minimumRepaintInterval() const {return min_repaint_int;} - int histogramMinIntervals() const {return min_int;} - int histogramMaxIntervals() const {return max_int;} - double histogramMinDeltaMultiplier() const {return mdm;} double gridNumbersMultiplierX() const {return grid_numbers_x;} double gridNumbersMultiplierY() const {return grid_numbers_y;} Graduation graduationX() const {return grad_x;} @@ -212,17 +205,10 @@ public: QWidget * viewport() const {return canvas;} QByteArray save(); void load(QByteArray ba); - ///void lock() {mutex_.lock();} - ///void unlock() {mutex_.unlock();} - - ///void reset() {mutex.lock(); clear(); mutex.unlock();} - void reset() {clear();} GraphicType graphic(int arg) {if (arg < 0 || arg >= graphics.size()) return GraphicType(); return graphics[arg];} const QVector & allGraphics() const {return graphics;} void setAllGraphics(const QVector & g, bool update = true) {graphics = g; if (update) updateLegend();} -// void setHistogramData(const QVector & g, int graphic); -// void setHistogramData(const QVector & g) {setHistogramData(g, curGraphic);} double canvas2realX(double px) const; double canvas2realY(double py) const; @@ -295,9 +281,6 @@ public slots: void setOnlyExpandY(bool yes); void setOnlyExpandX(bool yes); void setGesturesNavigation(bool yes); - void setHistogramMinIntervals(int value) {min_int = value; updateGraphics();} - void setHistogramMaxIntervals(int value) {max_int = value; updateGraphics();} - void setHistogramMinDeltaMultiplier(double value) {mdm = value; updateGraphics();} void setGraphicsData(const GraphicsData & gd); void setGraphicsDataRaw(const QByteArray & ba); @@ -376,8 +359,6 @@ protected: Ui::Graphic * ui; UGLWidget * canvas_gl; - ///QMutex mutex, mutex_; - QDialog * fullscr_dialog; QWidget * canvas; QImage * buffer; QPainter * painter; @@ -387,7 +368,7 @@ protected: QVector graphics; int curGraphic; GraphicAction curaction, prevaction; - QRectF grect, rrect, selrect, limit_, def_rect; + QRectF grect, selrect, limit_, def_rect; QRect margins_; QSize font_sz; QPoint startpos, curpos, prevpos, gridborder; @@ -397,15 +378,15 @@ protected: Graphic::Alignment align; GraphicConf * conf; EvalSpinBox line_x_min, line_x_max, line_y_min, line_y_max; - QTime tm, tm_fscr; + QElapsedTimer tm; QIcon icon_exp_x, icon_exp_y, icon_exp_sx, icon_exp_sy; QImage icon_pause_b, icon_pause_f; Graduation grad_x, grad_y; AxisType axis_type_x; - double gridx, gridy, history, visible_time, inc_x, mdm, grid_numbers_x, grid_numbers_y, LN2, LN5, LN10; + double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10; double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle; - int legy, lastw, lasth, min_repaint_int, min_int, max_int, timer_pause, thick; - bool aalias, aupdate, mupdate, grid, guides, isFit, isEmpty, isOGL, isHover, bufferActive, cancel, pause_, isPrinting, gestures; + int lastw, lasth, min_repaint_int, timer_pause, thick; + bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures; bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan; protected slots: @@ -424,7 +405,7 @@ protected slots: void lineYMinChanged(double value) {selrect.setBottom(value); checkLines();} void lineYMaxChanged(double value) {selrect.setTop(value); checkLines();} void on_buttonClose_clicked() {emit closeRequest(this);} - void on_buttonClear_clicked() {reset(); emit cleared();} + void on_buttonClear_clicked() {clear(); emit cleared();} void on_buttonAutofit_clicked(); void on_buttonConfigure_clicked(); void on_buttonFullscreen_clicked() {fullscreen();} diff --git a/qad/graphic/qpicalculator/mainwindow.cpp b/qad/graphic/qpicalculator/mainwindow.cpp index db6dd80..4381f41 100644 --- a/qad/graphic/qpicalculator/mainwindow.cpp +++ b/qad/graphic/qpicalculator/mainwindow.cpp @@ -129,7 +129,7 @@ void MainWindow::saving(QPIConfig & conf) { vc = treeGraphics->topLevelItemCount(); for (int i = 0; i < vc; ++i) { QTreeWidgetItem * ti = treeGraphics->topLevelItem(i); - vars << QString::number(ti->backgroundColor(1).rgb()) << ti->text(2); + vars << QString::number(ti->background(1).color().rgb()) << ti->text(2); } QByteArray ba; QDataStream s(&ba, QIODevice::WriteOnly); s << graphic->allGraphics(); diff --git a/qad/icons/select-all.png b/qad/icons/select-all.png new file mode 100644 index 0000000..c045ff1 Binary files /dev/null and b/qad/icons/select-all.png differ diff --git a/qad/icons/select-none.png b/qad/icons/select-none.png new file mode 100644 index 0000000..cf65075 Binary files /dev/null and b/qad/icons/select-none.png differ