Prevent creation of superflous QGItems for Text Fields

This commit is contained in:
WandererFan 2016-08-11 09:41:58 -04:00 committed by wmayer
parent ef69519261
commit d8ccf14ec3
5 changed files with 51 additions and 38 deletions

View File

@ -49,7 +49,8 @@ using namespace TechDrawGui;
QGISVGTemplate::QGISVGTemplate(QGraphicsScene *scene, QWidget* srWidget)
: QGITemplate(scene),
qgview(srWidget)
qgview(srWidget),
firstTime(true)
{
m_svgItem = new QGraphicsSvgItem(this);
@ -69,7 +70,7 @@ QGISVGTemplate::~QGISVGTemplate()
}
QVariant QGISVGTemplate::itemChange(GraphicsItemChange change,
const QVariant &value)
const QVariant &value)
{
return QGraphicsItemGroup::itemChange(change, value);
}
@ -95,10 +96,50 @@ void QGISVGTemplate::load(const QString &fileName)
QSize size = m_svgRender->defaultSize();
m_svgItem->setSharedRenderer(m_svgRender);
if (firstTime) {
createClickHandles();
firstTime = false;
}
//This is probably first time only logic too.
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
double xaspect, yaspect;
xaspect = tmplte->getWidth() / (double) size.width();
yaspect = tmplte->getHeight() / (double) size.height();
QTransform qtrans;
qtrans.translate(0.f, -tmplte->getHeight());
qtrans.scale(xaspect , yaspect);
m_svgItem->setTransform(qtrans);
}
TechDraw::DrawSVGTemplate * QGISVGTemplate::getSVGTemplate()
{
if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId()))
return static_cast<TechDraw::DrawSVGTemplate *>(pageTemplate);
else
return 0;
}
void QGISVGTemplate::draw()
{
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
if(!tmplte)
throw Base::Exception("Template Feature not set for QGISVGTemplate");
load(QString::fromUtf8(tmplte->PageResult.getValue()));
}
void QGISVGTemplate::updateView(bool update)
{
draw();
}
void QGISVGTemplate::createClickHandles(void)
{
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
std::string temp = tmplte->PageResult.getValue();
std::string temp = tmplte->PageResult.getValue(); //fixes non-drawing of restored template
if (temp.empty())
return;
@ -108,13 +149,14 @@ void QGISVGTemplate::load(const QString &fileName)
std::string tempendl = "--endOfLine--";
std::string line;
//read all of PageResult into oStream (except the DrawingContent marker comment - why??)
std::ifstream ifile (fi.filePath().c_str());
while (!ifile.eof())
{
std::getline(ifile,line);
// check if the marker in the template is found
if(line.find("<!-- DrawingContent -->") == std::string::npos) {
// if not - write through
// if not - write line to oStream
oStream << line << tempendl;
}
}
@ -139,7 +181,6 @@ void QGISVGTemplate::load(const QString &fileName)
//TODO: Find location of special fields (first/third angle) and make graphics items for them
// and update the sketch
while (boost::regex_search(begin, end, tagMatch, tagRegex)) {
if ( boost::regex_search(tagMatch[1].first, tagMatch[1].second, nameMatch, editableNameRegex) &&
boost::regex_search(tagMatch[1].first, tagMatch[1].second, xMatch, xRegex) &&
@ -180,36 +221,6 @@ void QGISVGTemplate::load(const QString &fileName)
begin = tagMatch[0].second;
}
double xaspect, yaspect;
xaspect = tmplte->getWidth() / (double) size.width();
yaspect = tmplte->getHeight() / (double) size.height();
QTransform qtrans;
qtrans.translate(0.f, -tmplte->getHeight());
qtrans.scale(xaspect , yaspect);
m_svgItem->setTransform(qtrans);
}
TechDraw::DrawSVGTemplate * QGISVGTemplate::getSVGTemplate()
{
if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId()))
return static_cast<TechDraw::DrawSVGTemplate *>(pageTemplate);
else
return 0;
}
void QGISVGTemplate::draw()
{
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
if(!tmplte)
throw Base::Exception("Template Feature not set for QGISVGTemplate");
load(QString::fromUtf8(tmplte->PageResult.getValue()));
}
void QGISVGTemplate::updateView(bool update)
{
draw();
}
#include <Mod/TechDraw/Gui/moc_QGISVGTemplate.cpp>

View File

@ -55,9 +55,11 @@ public:
protected:
void openFile(const QFile &file);
void load (const QString & fileName);
void createClickHandles(void);
QWidget* qgview; //for parenting dlgTemplateField
protected:
bool firstTime;
TechDraw::DrawSVGTemplate * getSVGTemplate();
QGraphicsSvgItem *m_svgItem;
QSvgRenderer *m_svgRender;

View File

@ -37,7 +37,7 @@
using namespace TechDrawGui;
QGITemplate::QGITemplate(QGraphicsScene *scene) : QGraphicsItemGroup(),
pageTemplate(0)
pageTemplate(0)
{
setHandlesChildEvents(false);
setCacheMode(QGraphicsItem::NoCache);

View File

@ -57,7 +57,7 @@ public:
inline qreal getY() { return y() * -1; }
virtual void updateView(bool update = false);
std::vector<TemplateTextField *> getTestFields(void) { return textFields; };
std::vector<TemplateTextField *> getTextFields(void) { return textFields; };
virtual void draw() = 0;

View File

@ -442,7 +442,7 @@ void QGVPage::toggleMarkers(bool enable)
}
QGISVGTemplate* itemTemplate = dynamic_cast<QGISVGTemplate*> (*it);
if (itemTemplate) {
std::vector<TemplateTextField *> textFields = itemTemplate->getTestFields();
std::vector<TemplateTextField *> textFields = itemTemplate->getTextFields();
for (auto& t:textFields) {
if (enable) {
t->show();