Menu

[efa3d9]: / src / flag.cpp  Maximize  Restore  History

Download this file

149 lines (111 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "flag.h"
#include "file.h"
#include "image-container.h"
#include <QDebug>
/////////////////////////////////////////////////////////////////
// Flag
/////////////////////////////////////////////////////////////////
Flag::Flag()
{
// qDebug() << "Const Flag ()";
init();
}
Flag::Flag(const QString &fname)
{
//qDebug() << "Const Flag (fname)" << fname;
init();
if (!load(fname))
qWarning() << "Flag::Flag Failed to load " << fname;
}
Flag::~Flag()
{
// qDebug() << "Destr Flag this="<<this <<" " << qPrintable(name) << "
// imageContainer=" << imageContainer;
if (imageContainer)
delete imageContainer;
}
void Flag::init()
{
action = nullptr;
name = "undefined";
visible = true;
unsetGroup();
imageContainer = nullptr;
state = false;
used = false;
type = UndefinedFlag;
uuid = QUuid::createUuid();
}
bool Flag::load(const QString &fn)
{
if (!imageContainer)
imageContainer = new ImageContainer();
if (!imageContainer->load(fn))
return false;
if (fn.contains("svg")) {
imageContainer->setWidth(32);
}
path = fn;
return true;
}
void Flag::setName(const QString &n)
{
name = n;
if (name.contains("/"))
name = basename(name);
name = name.section('.', 0, 0);
}
const QString Flag::getName() { return name; }
const QString Flag::getPath() { return path; }
void Flag::setVisible(bool b) { visible = b; }
bool Flag::isVisible() { return visible; }
void Flag::setGroup(const QString &n) { group = n; }
const QString Flag::getGroup() { return group; }
void Flag::unsetGroup() { group.clear(); }
void Flag::setToolTip(const QString &n) { tooltip = n; }
const QString Flag::getToolTip() { return tooltip; }
ImageContainer *Flag::getImageContainer()
{
if (imageContainer)
return imageContainer;
else
return nullptr;
}
void Flag::setAction(QAction *a) { action = a; }
QAction *Flag::getAction() { return action; }
void Flag::setUsed(bool b) { used = b; }
bool Flag::isUsed() { return used; }
Flag::FlagType Flag::getType() { return type; }
void Flag::setType(Flag::FlagType t) { type = t; }
void Flag::setUuid(const QUuid &id) { uuid = id; }
QUuid Flag::getUuid() { return uuid; }
QString Flag::getDefinition(const QString &prefix)
{
if (type == Flag::UserFlag) {
QString url = "flags/" + prefix + uuid.toString() + "-" + name +
imageContainer->getExtension();
QStringList attributes;
attributes << attribute("name", name);
attributes << attribute("href", QString("file:%1").arg(url));
attributes << attribute("uuid", uuid.toString());
return singleElement("userflagdef", attributes);
}
else
return QString();
}
void Flag::saveDataToDir(const QString &dirPath)
{
if (imageContainer) {
path = dirPath + "/" + uuid.toString() + "-" + name +
imageContainer->getExtension();
imageContainer->save(path);
}
}
QString Flag::saveState()
{
if (type == Flag::UserFlag)
return singleElement("userflag", attribute("name", name) +
attribute("uuid", uuid.toString()));
else
return valueElement("standardflag", name);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.