Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
geometrize::RecentItems::RecentItemsImpl Class Reference

Public Member Functions

 RecentItemsImpl (const QString &group, unsigned int maxItems)
 
 ~RecentItemsImpl ()=default
 
RecentItemsImploperator= (const RecentItemsImpl &)=delete
 
 RecentItemsImpl (const RecentItemsImpl &)=delete
 
QList< RecentItemgetItems () const
 
bool contains (const QString &value) const
 
RecentItem addItem (const QString &itemId, const QString &itemDisplayName)
 
void removeItem (const QString &value)
 
void clearItems ()
 
unsigned int getItemCount () const
 
unsigned int getMaxItemCount () const
 
QString getOldestItemKey () const
 

Static Private Member Functions

static QString getItemGroup ()
 
static QString msSinceEpochAsString ()
 
static long long int msSinceEpoch ()
 
static QString getId ()
 

Private Attributes

const QString m_group
 The base path group for storing the recent items in settings e.g. "recent_image_paths" etc. More...
 
const unsigned int m_maxItems
 The maximum number of items. More...
 

Static Private Attributes

static const QString ID_KEY {"id"}
 Key for the path or URL to the item. More...
 
static const QString DISPLAY_NAME_KEY {"displayname"}
 Key for the display name of the item. More...
 
static const QString TIME_STAMP_KEY {"timestamp"}
 Key for the timestamp of when the item was added or replaced. More...
 

Constructor & Destructor Documentation

geometrize::RecentItems::RecentItemsImpl::RecentItemsImpl ( const QString &  group,
unsigned int  maxItems 
)
inline
16  : m_group{group}, m_maxItems{maxItems}
17  {
18  assert(m_group.length() > 0 && "Base group cannot be empty");
19  assert(!m_group.contains('/') && "Base group must not contain forward slashes");
20  assert(!m_group.contains('\\') && "Base group must not contain backslashes");
21  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
const unsigned int m_maxItems
The maximum number of items.
Definition: recentitems.cpp:153
geometrize::RecentItems::RecentItemsImpl::~RecentItemsImpl ( )
default
geometrize::RecentItems::RecentItemsImpl::RecentItemsImpl ( const RecentItemsImpl )
delete

Member Function Documentation

RecentItem geometrize::RecentItems::RecentItemsImpl::addItem ( const QString &  itemId,
const QString &  itemDisplayName 
)
inline
65  {
66  const RecentItem item(itemId, itemDisplayName, msSinceEpoch());
67  const QString group{getItemGroup()};
68 
69  QSettings settings;
70  settings.beginGroup(m_group);
71  settings.beginGroup(group);
72 
73  settings.setValue(ID_KEY, QVariant(item.getKey()));
74  settings.setValue(DISPLAY_NAME_KEY, QVariant(item.getDisplayName()));
75  settings.setValue(TIME_STAMP_KEY, QVariant(item.getTimeStamp()));
76 
77  settings.endGroup();
78  settings.endGroup();
79 
80  return item;
81  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
static const QString TIME_STAMP_KEY
Key for the timestamp of when the item was added or replaced.
Definition: recentitems.cpp:157
static const QString ID_KEY
Key for the path or URL to the item.
Definition: recentitems.cpp:155
static QString getItemGroup()
Definition: recentitems.cpp:131
static const QString DISPLAY_NAME_KEY
Key for the display name of the item.
Definition: recentitems.cpp:156
static long long int msSinceEpoch()
Definition: recentitems.cpp:141

Here is the call graph for this function:

void geometrize::RecentItems::RecentItemsImpl::clearItems ( )
inline
99  {
100  QSettings settings;
101  settings.beginGroup(m_group);
102  settings.remove("");
103  settings.endGroup();
104  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
bool geometrize::RecentItems::RecentItemsImpl::contains ( const QString &  value) const
inline
48  {
49  QSettings settings;
50  settings.beginGroup(m_group);
51  const QStringList childGroups{settings.childGroups()};
52  for(const QString& group : childGroups) {
53  settings.beginGroup(group);
54  if(settings.value(ID_KEY) == value) {
55  return true;
56  }
57  settings.endGroup();
58  }
59  settings.endGroup();
60 
61  return false;
62  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
static const QString ID_KEY
Key for the path or URL to the item.
Definition: recentitems.cpp:155
static QString geometrize::RecentItems::RecentItemsImpl::getId ( )
inlinestaticprivate
147  {
148  static std::atomic<std::size_t> id{0U};
149  return QString::number(id++);
150  }

Here is the caller graph for this function:

unsigned int geometrize::RecentItems::RecentItemsImpl::getItemCount ( ) const
inline
107  {
108  QSettings settings;
109  settings.beginGroup(m_group);
110  const int count{settings.childGroups().length()};
111  settings.endGroup();
112 
113  return count;
114  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
static QString geometrize::RecentItems::RecentItemsImpl::getItemGroup ( )
inlinestaticprivate
132  {
133  return msSinceEpochAsString() + "_" + getId();
134  }
static QString msSinceEpochAsString()
Definition: recentitems.cpp:136
static QString getId()
Definition: recentitems.cpp:146

Here is the call graph for this function:

Here is the caller graph for this function:

QList<RecentItem> geometrize::RecentItems::RecentItemsImpl::getItems ( ) const
inline
28  {
29  QSettings settings;
30  settings.beginGroup(m_group);
31  const QStringList childGroups{settings.childGroups()};
32  QList<RecentItem> recentItems;
33  for(const QString& group : childGroups) {
34  settings.beginGroup(group);
35  const RecentItem item(settings.value(ID_KEY, "").toString(), settings.value(DISPLAY_NAME_KEY, "").toString(), settings.value(TIME_STAMP_KEY, 0).toLongLong());
36  settings.endGroup();
37  recentItems.push_back(item);
38  }
39  settings.endGroup();
40 
41  std::sort(recentItems.begin(), recentItems.end(), [](const RecentItem& a, const RecentItem& b) {
42  return a.getTimeStamp() < b.getTimeStamp();
43  });
44  return recentItems;
45  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
static const QString TIME_STAMP_KEY
Key for the timestamp of when the item was added or replaced.
Definition: recentitems.cpp:157
static const QString ID_KEY
Key for the path or URL to the item.
Definition: recentitems.cpp:155
static const QString DISPLAY_NAME_KEY
Key for the display name of the item.
Definition: recentitems.cpp:156

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int geometrize::RecentItems::RecentItemsImpl::getMaxItemCount ( ) const
inline
117  {
118  return m_maxItems;
119  }
const unsigned int m_maxItems
The maximum number of items.
Definition: recentitems.cpp:153
QString geometrize::RecentItems::RecentItemsImpl::getOldestItemKey ( ) const
inline
122  {
123  QList<RecentItem> items{getItems()};
124  if(items.empty()) {
125  return "";
126  }
127  return items.front().getKey();
128  }
QList< RecentItem > getItems() const
Definition: recentitems.cpp:27

Here is the call graph for this function:

static long long int geometrize::RecentItems::RecentItemsImpl::msSinceEpoch ( )
inlinestaticprivate
142  {
143  return QDateTime::currentMSecsSinceEpoch();
144  }

Here is the caller graph for this function:

static QString geometrize::RecentItems::RecentItemsImpl::msSinceEpochAsString ( )
inlinestaticprivate
137  {
138  return QString::number(msSinceEpoch());
139  }
static long long int msSinceEpoch()
Definition: recentitems.cpp:141

Here is the call graph for this function:

Here is the caller graph for this function:

RecentItemsImpl& geometrize::RecentItems::RecentItemsImpl::operator= ( const RecentItemsImpl )
delete
void geometrize::RecentItems::RecentItemsImpl::removeItem ( const QString &  value)
inline
84  {
85  QSettings settings;
86  settings.beginGroup(m_group);
87  const QStringList childGroups{settings.childGroups()};
88  for(const QString& group : childGroups) {
89  settings.beginGroup(group);
90  if(settings.value(ID_KEY) == value) {
91  settings.remove("");
92  }
93  settings.endGroup();
94  }
95  settings.endGroup();
96  }
const QString m_group
The base path group for storing the recent items in settings e.g. "recent_image_paths" etc...
Definition: recentitems.cpp:152
static const QString ID_KEY
Key for the path or URL to the item.
Definition: recentitems.cpp:155

Member Data Documentation

const QString geometrize::RecentItems::RecentItemsImpl::DISPLAY_NAME_KEY {"displayname"}
staticprivate

Key for the display name of the item.

const QString geometrize::RecentItems::RecentItemsImpl::ID_KEY {"id"}
staticprivate

Key for the path or URL to the item.

const QString geometrize::RecentItems::RecentItemsImpl::m_group
private

The base path group for storing the recent items in settings e.g. "recent_image_paths" etc.

const unsigned int geometrize::RecentItems::RecentItemsImpl::m_maxItems
private

The maximum number of items.

const QString geometrize::RecentItems::RecentItemsImpl::TIME_STAMP_KEY {"timestamp"}
staticprivate

Key for the timestamp of when the item was added or replaced.


The documentation for this class was generated from the following file: