Skip to content

Commit

Permalink
Some improvements concerning markers
Browse files Browse the repository at this point in the history
The new features of this PR are the following:
i) Markers can take another marker as reference (delta mode)
ii) The user is allowed to change the color and linewidth of the marker
iii) Most (if not all) of Qt warnings were removed

Updated Marker code

The aim of this commit is to upgrade the marker code so as to let the
user to include the value of the marker in the default dataset. It is
also possible to assign manually an ID for each marker

Added color and linewidth properties

New delta marker feature

...code improvements needed

Complex delta markers is fully working

The implementation of delta markers is completed. Some code debugging is
still needed.

Corrected some annoying bugs...

Cleaning up warnings...

Those warnings related to Marker, DiagramDialog and MarkerDialog classes
were fixed
  • Loading branch information
andresmmera committed Jan 1, 2016
1 parent 6c8badc commit eccc5f1
Show file tree
Hide file tree
Showing 9 changed files with 555 additions and 157 deletions.
67 changes: 62 additions & 5 deletions qucs/qucs/diagrams/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
#include <QDateTime>
#include <QPainter>
#include <QDebug>
#include <QFile>
#include <QTextStream>

Diagram::Diagram(int _cx, int _cy)
{
cx = _cx; cy = _cy;

// x1, x2, y1, y2 are the selectable boundings of the diagram, but these
// are the real boundings. They are set in "createAxisLabels()".
Bounding_x1 = Bounding_x2 = Bounding_y1 = Bounding_y2 = 0;
Expand All @@ -80,12 +81,17 @@ Diagram::Diagram(int _cx, int _cy)
Type = isDiagram;
isSelected = false;
GridPen = QPen(Qt::lightGray,0);
Nmarkers=0;
}


Diagram::~Diagram()
{
{//Whenever the diagram is deleted, the marker registry must be updated
RemoveMarkersFromDataset(MarkerIDs);
}



/*!
Paint function for most diagrams (cartesian, smith, polar, ...)
*/
Expand Down Expand Up @@ -128,10 +134,23 @@ void Diagram::paint(ViewPainter *p)
p->Painter->restore();

// draw markers last, so they are at the top of painting layers
foreach(Graph *pg, Graphs)

// Get all active markers in the diagram
Nmarkers=0;
QList <QString> ActiveMarkers;
foreach(Graph *pg, Graphs)
foreach(Marker *pm, pg->Markers)
{
pm->paint(p, cx, cy);
Nmarkers++;
ActiveMarkers.append(pm->getID());
}

//Compare the list of active markers with the list of registered markers. The intersection must
// be removed from the dataset
QSet <QString> oldMarkers = MarkerIDs.toSet() - ActiveMarkers.toSet();
MarkerIDs = ActiveMarkers;
RemoveMarkersFromDataset(oldMarkers.toList());//Updates the registry of markers. The diagram object has no clue about the removed markers, so this is kinda trick...

if(isSelected) {
int x_, y_;
Expand All @@ -150,6 +169,38 @@ void Diagram::paint(ViewPainter *p)
}
}

void Diagram::RemoveMarkersFromDataset(QList<QString> OldMarkers)
{
QString DatasetPath=DefaultDataset.mid(0,DefaultDataset.length()-4) + QString(".Markers.dat");
QFile file(DatasetPath);//Opens the default dataset for updating the content
if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
return;

//Search MarkerID in the dataset
QTextStream in(&file);
QString s = "";
while (!in.atEnd())
{
QString line = in.readLine();
QString tmpVar = line.section(' ',1,1).section('.', 0,0);
if (OldMarkers.indexOf(tmpVar)!=-1)//Then it must be removed
{
in.readLine();
in.readLine();
}
else
{
s.append(line + "\n");
s.append(in.readLine() + "\n");
s.append(in.readLine() + "\n");
}
}

file.resize(0);
in << s;
file.close();
}

// ------------------------------------------------------------
void Diagram::paintScheme(Schematic *p)
{
Expand Down Expand Up @@ -318,15 +369,16 @@ bool Diagram::insideDiagram(float x, float y) const
/*!
(try to) set a Marker to a diagram
*/
Marker* Diagram::setMarker(int x, int y)
Marker* Diagram::setMarker(int x, int y, QString markerID)
{
if(getSelected(x, y)) {
// test all graphs of the diagram
foreach(Graph *pg,Graphs) {
int n = pg->getSelected(x-cx, cy-y); // sic!
if(n >= 0) {
assert(pg->parentDiagram() == this);
Marker *pm = new Marker(pg, n, x-cx, y-cy);
Marker *pm = new Marker(pg, n, x-cx, y-cy, markerID);
MarkerIDs.append(markerID);
pg->Markers.append(pm);
return pm;
}
Expand Down Expand Up @@ -679,6 +731,7 @@ void Diagram::loadGraphData(const QString& defaultDataSet)
int yNum = yAxis.numGraphs;
int zNum = zAxis.numGraphs;
yAxis.numGraphs = zAxis.numGraphs = 0;
DefaultDataset = defaultDataSet;

double xmin = xAxis.min, ymin = yAxis.min, zmin = zAxis.min;
double xmax = xAxis.max, ymax = yAxis.max, zmax = zAxis.max;
Expand Down Expand Up @@ -1357,11 +1410,14 @@ bool Diagram::load(const QString& Line, QTextStream *stream)
if(!pg) return false;
assert(pg->parentDiagram() == this);
Marker *pm = new Marker(pg);
QString DatasetName=DefaultDataset.mid(0,DefaultDataset.length()-4) + QString(".Markers.dat");
pm->setDataset(DatasetName);
if(!pm->load(s)) {
delete pm;
return false;
}
pg->Markers.append(pm);
Nmarkers++;
continue;
}

Expand Down Expand Up @@ -1960,3 +2016,4 @@ void Diagram::calcCoordinateP (const double*x, const double*y, const double*z, G


// vim:ts=8:sw=2:noet

12 changes: 8 additions & 4 deletions qucs/qucs/diagrams/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Diagram : public Element {
public:
Diagram(int _cx=0, int _cy=0);
virtual ~Diagram();

QString DefaultDataset;
virtual Diagram* newOne();
virtual int calcDiagram() { return 0; };
virtual void calcCoordinate
Expand All @@ -79,21 +79,24 @@ class Diagram : public Element {
bool resizeTouched(float, float, float);
QString save();
bool load(const QString&, QTextStream*);

void getAxisLimits(Graph*);
void updateGraphData();
void loadGraphData(const QString&);
//void loadMarkerData(QString);
void recalcGraphData();
bool sameDependencies(Graph const*, Graph const*) const;
int checkColumnWidth(const QString&, const QFontMetrics&, int, int, int);
void RemoveMarkersFromDataset(QList<QString>);

QList<QString> MarkerIDs;

virtual bool insideDiagram(float, float) const;
bool insideDiagramP(Graph::iterator const& ) const;
Marker* setMarker(int x, int y);
Marker* setMarker(int x, int y, QString markerID);

QString Name; // identity of diagram type (e.g. Polar), used for saving etc.
QPen GridPen;

int Nmarkers;
QList<Graph *> Graphs;
QList<Arc *> Arcs;
QList<Line *> Lines;
Expand Down Expand Up @@ -123,6 +126,7 @@ class Diagram : public Element {

virtual void calcData(Graph*);


private:
int Bounding_x1, Bounding_x2, Bounding_y1, Bounding_y2;
};
Expand Down
Loading

0 comments on commit eccc5f1

Please sign in to comment.