r23683 by craig - ScLayer code cleanup
scribus-commit
scribus-commit at lists.scribus.net
Sun May 3 19:24:40 UTC 2020
Author: craig
Date: Sun May 3 19:24:40 2020
New Revision: 23683
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23683
Log:
ScLayer code cleanup
Modified:
trunk/Scribus/scribus/sclayer.cpp
trunk/Scribus/scribus/sclayer.h
Modified: trunk/Scribus/scribus/sclayer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23683&path=/trunk/Scribus/scribus/sclayer.cpp
==============================================================================
--- trunk/Scribus/scribus/sclayer.cpp (original)
+++ trunk/Scribus/scribus/sclayer.cpp Sun May 3 19:24:40 2020
@@ -16,18 +16,7 @@
ScLayer::ScLayer()
{
- Name = QObject::tr("New Layer");
- ID = 0;
- Level = 0;
- isPrintable = true;
- isViewable = true;
- isEditable = true;
- isSelectable = false;
- flowControl = true;
- outlineMode = false;
- transparency = 1.0;
- blendMode = 0;
- markerColor = QColor(0, 0, 0);
+ Name = QObject::tr("New Layer");
}
ScLayer::ScLayer(const QString& name, int level, int id)
@@ -35,15 +24,6 @@
Name = name;
ID = id;
Level = level;
- isPrintable = true;
- isViewable = true;
- isEditable = true;
- isSelectable = false;
- flowControl = true;
- outlineMode = false;
- transparency = 1.0;
- blendMode = 0;
- markerColor = QColor(0, 0, 0);
switch (ID % 7)
{
case 0:
@@ -79,18 +59,18 @@
{
// ignore markerColor?
return Name == other.Name && ID == other.ID && Level == other.Level &&
- isPrintable == other.isPrintable && isViewable == other.isViewable &&
- flowControl == other.flowControl && outlineMode == other.outlineMode &&
- transparency == other.transparency && isEditable == other.isEditable &&
- blendMode == other.blendMode;
+ isPrintable == other.isPrintable && isViewable == other.isViewable &&
+ flowControl == other.flowControl && outlineMode == other.outlineMode &&
+ transparency == other.transparency && isEditable == other.isEditable &&
+ blendMode == other.blendMode;
}
int ScLayers::getMaxID()
{
- int nr, maxNr = -1;
- for (int i = 0; i < this->count(); ++i)
- {
- nr = this->at(i).ID;
+ int maxNr = -1;
+ for (int i = 0; i < this->count(); ++i)
+ {
+ int nr = this->at(i).ID;
if (nr > maxNr)
maxNr = nr;
}
@@ -192,45 +172,41 @@
ScLayer* ScLayers::above (int nr)
{
ScLayer* lyr = byID(nr);
- if (lyr)
- {
- ScLayer *rlyr = top();
- int level = lyr->Level;
- int maxLevel = rlyr->Level;
- ScLayers::Iterator it, itEnd = end();
- for (it = begin(); it != itEnd; ++it)
- {
- if (it->Level > level && it->Level < maxLevel)
- {
- maxLevel = it->Level;
- rlyr = &(*it);
- }
- }
- return rlyr;
- }
- return nullptr;
+ if (!lyr)
+ return nullptr;
+ ScLayer *rlyr = top();
+ int level = lyr->Level;
+ int maxLevel = rlyr->Level;
+ ScLayers::Iterator it, itEnd = end();
+ for (it = begin(); it != itEnd; ++it)
+ {
+ if (it->Level > level && it->Level < maxLevel)
+ {
+ maxLevel = it->Level;
+ rlyr = &(*it);
+ }
+ }
+ return rlyr;
}
ScLayer* ScLayers::below (int nr)
{
ScLayer* lyr = byID(nr);
- if (lyr)
- {
- ScLayer *rlyr = bottom();
- int level = lyr->Level;
- int minLevel = lyr->Level;
- ScLayers::Iterator it, itEnd = end();
- for (it = begin(); it != itEnd; ++it)
- {
- if (it->Level < level && it->Level > minLevel)
- {
- minLevel = it->Level;
- rlyr = &(*it);
- }
- }
- return rlyr;
- }
- return nullptr;
+ if (!lyr)
+ return nullptr;
+ ScLayer *rlyr = bottom();
+ int level = lyr->Level;
+ int minLevel = lyr->Level;
+ ScLayers::Iterator it, itEnd = end();
+ for (it = begin(); it != itEnd; ++it)
+ {
+ if (it->Level < level && it->Level > minLevel)
+ {
+ minLevel = it->Level;
+ rlyr = &(*it);
+ }
+ }
+ return rlyr;
}
const ScLayer* ScLayers::layerByLevel (int level) const
@@ -293,66 +269,61 @@
const ScLayer* ScLayers::layerAbove (const ScLayer& layer) const
{
const ScLayer* top = topLayer();
- if (top)
- {
- const ScLayer *curlay, *retlay = top;
- int level = layer.Level;
- int maxLevel = top->Level;
- for (int i = 0; i < this->count(); ++i)
- {
- curlay = &this->at(i);
- if (curlay->Level > level && curlay->Level < maxLevel)
- {
- maxLevel = curlay->Level;
- retlay = curlay;
- }
- }
- return retlay;
- }
- return nullptr;
+ if (!top)
+ return nullptr;
+ const ScLayer *curlay, *retlay = top;
+ int level = layer.Level;
+ int maxLevel = top->Level;
+ for (int i = 0; i < this->count(); ++i)
+ {
+ curlay = &this->at(i);
+ if (curlay->Level > level && curlay->Level < maxLevel)
+ {
+ maxLevel = curlay->Level;
+ retlay = curlay;
+ }
+ }
+ return retlay;
}
const ScLayer* ScLayers::layerBelow (int level) const
{
const ScLayer* bottom = bottomLayer();
- if (bottom)
- {
- const ScLayer *layer, *retlay = bottom;
- int minLevel = bottom->Level;
- for (int i = 0; i < this->count(); ++i)
- {
- layer = &this->at(i);
- if (layer->Level < level && layer->Level > minLevel)
- {
- minLevel = layer->Level;
- retlay = layer;
- }
- }
- return retlay;
- }
- return nullptr;
+ if (!bottom)
+ return nullptr;
+ const ScLayer *layer, *retlay = bottom;
+ int minLevel = bottom->Level;
+ for (int i = 0; i < this->count(); ++i)
+ {
+ layer = &this->at(i);
+ if (layer->Level < level && layer->Level > minLevel)
+ {
+ minLevel = layer->Level;
+ retlay = layer;
+ }
+ }
+ return retlay;
}
const ScLayer* ScLayers::layerBelow (const ScLayer& layer) const
{
const ScLayer* bottom = bottomLayer();
- if (bottom)
- {
- const ScLayer *curlay, *retlay = bottom;
- int level = layer.Level;
- int minLevel = bottom->Level;
- for (int i = 0; i < this->count(); ++i)
- {
- curlay = &this->at(i);
- if (curlay->Level < level && curlay->Level > minLevel)
- {
- minLevel = curlay->Level;
- retlay = curlay;
- }
- }
- return retlay;
- }
- return nullptr;
+ if (!bottom)
+ return nullptr;
+
+ const ScLayer *curlay, *retlay = bottom;
+ int level = layer.Level;
+ int minLevel = bottom->Level;
+ for (int i = 0; i < this->count(); ++i)
+ {
+ curlay = &this->at(i);
+ if (curlay->Level < level && curlay->Level > minLevel)
+ {
+ minLevel = curlay->Level;
+ retlay = curlay;
+ }
+ }
+ return retlay;
}
int ScLayers::addLayer(const QString& layerName)
@@ -365,7 +336,7 @@
int ScLayers::addLayer(const ScLayer& layer)
{
- int newID = layer.ID;
+ int newID = layer.ID;
const ScLayer* lid = layerByID(newID);
if (lid)
{
@@ -382,8 +353,8 @@
ScLayer* ScLayers::newLayer(const QString& layerName)
{
QString lname;
- int lId = getMaxID() + 1;
- int llevel = count();
+ int lId = getMaxID() + 1;
+ int llevel = count();
if (layerName.isEmpty())
{
QString tmp;
@@ -488,172 +459,154 @@
bool ScLayers::layerPrintable(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->isPrintable;
- return false;
+ if (!layer)
+ return false;
+ return layer->isPrintable;
}
bool ScLayers::setLayerPrintable(int layerID, bool isPrintable)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->isPrintable = isPrintable;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->isPrintable = isPrintable;
+ return true;
}
bool ScLayers::layerVisible(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->isViewable;
- return false;
+ if (!layer)
+ return false;
+ return layer->isViewable;
}
bool ScLayers::setLayerVisible(int layerID, bool isViewable)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->isViewable = isViewable;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->isViewable = isViewable;
+ return true;
}
bool ScLayers::layerLocked(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return !(layer->isEditable);
- return false;
+ if (!layer)
+ return false;
+ return !(layer->isEditable);
}
bool ScLayers::setLayerLocked(int layerID, bool isLocked)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->isEditable = !isLocked;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->isEditable = !isLocked;
+ return true;
}
bool ScLayers::layerFlow(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->flowControl;
- return false;
+ if (!layer)
+ return false;
+ return layer->flowControl;
}
bool ScLayers::setLayerFlow(int layerID, bool flow)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->flowControl = flow;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->flowControl = flow;
+ return true;
}
bool ScLayers::layerOutline(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->outlineMode;
- return false;
+ if (!layer)
+ return false;
+ return layer->outlineMode;
}
bool ScLayers::setLayerOutline(int layerID, bool outline)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->outlineMode = outline;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->outlineMode = outline;
+ return true;
}
double ScLayers::layerTransparency(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->transparency;
- return 1.0;
+ if (!layer)
+ return 1.0;
+ return layer->transparency;
}
bool ScLayers::setLayerTransparency(int layerID, double trans)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->transparency = trans;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->transparency = trans;
+ return true;
}
int ScLayers::layerBlendMode(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->blendMode;
- return 0;
+ if (!layer)
+ return 0;
+ return layer->blendMode;
}
bool ScLayers::setLayerBlendMode(int layerID, int blend)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->blendMode = blend;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->blendMode = blend;
+ return true;
}
QColor ScLayers::layerMarker(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->markerColor;
- return Qt::black;
+ if (!layer)
+ return Qt::black;
+ return layer->markerColor;
}
bool ScLayers::setLayerMarker(int layerID, QColor color)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->markerColor = std::move(color);
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->markerColor = std::move(color);
+ return true;
}
bool ScLayers::layerSelectable(int layerID) const
{
const ScLayer* layer = layerByID(layerID);
- if (layer)
- return layer->isSelectable;
- return false;
+ if (!layer)
+ return false;
+ return layer->isSelectable;
}
bool ScLayers::setLayerSelectable(int layerID, bool isSelectable)
{
ScLayer* layer = byID(layerID);
- if (layer)
- {
- layer->isSelectable = isSelectable;
- return true;
- }
- return false;
+ if (!layer)
+ return false;
+ layer->isSelectable = isSelectable;
+ return true;
}
uint qHash(const ScLayer& layer)
Modified: trunk/Scribus/scribus/sclayer.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23683&path=/trunk/Scribus/scribus/sclayer.h
==============================================================================
--- trunk/Scribus/scribus/sclayer.h (original)
+++ trunk/Scribus/scribus/sclayer.h Sun May 3 19:24:40 2020
@@ -20,17 +20,17 @@
ScLayer(void);
ScLayer(const QString& name, int level, int id);
QString Name;
- int ID;
- int Level;
- bool isPrintable;
- bool isViewable;
- bool isEditable;
- bool isSelectable;
- bool flowControl;
- bool outlineMode;
- double transparency;
- int blendMode;
- QColor markerColor;
+ int ID {0};
+ int Level {0};
+ bool isPrintable {true};
+ bool isViewable {true};
+ bool isEditable {true};
+ bool isSelectable {false};
+ bool flowControl {true};
+ bool outlineMode {false};
+ double transparency {1.0};
+ int blendMode {0};
+ QColor markerColor;
bool operator< (const ScLayer& other) const;
bool operator== (const ScLayer& other) const;
};
@@ -244,10 +244,10 @@
/**
* @brief Set the layer locked via the layer ID
* @param layerID ID of the layer
- * @param isViewable true = layer is locked
+ * @param isLocked true = layer is locked
* @return bool Success or failure
*/
- bool setLayerLocked(int layerID, bool isViewable);
+ bool setLayerLocked(int layerID, bool isLocked);
/**
* @brief does text flow around objects on this layer
More information about the scribus-commit
mailing list