BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::Utils Namespace Reference

Collection of various widget-related utils. More...

Classes

struct  is_unique_ptr
 
struct  is_unique_ptr< std::unique_ptr< T, D > >
 

Functions

template<typename It , typename UnaryFunction >
std::vector< double > Apply (It begin, It end, UnaryFunction func)
 Returns vector containing results of elemntwise unary function application. More...
 
MVVM_MODEL_EXPORT bool AreAlmostEqual (double a, double b, double tolerance_factor=1.0)
 Returns true if two doubles agree within epsilon*tolerance. More...
 
MVVM_MODEL_EXPORT std::string base_name (const std::string &path)
 Provide the filename of a file path. More...
 
MVVM_MODEL_EXPORT void BeginMacros (const SessionItem *item, const std::string &macro_name)
 Begin undo/redo macros with given name. More...
 
template<typename T >
std::vector< T * > CastedItems (const std::vector< SessionItem * > &items)
 Returns vector of items casted to given type. More...
 
MVVM_VIEWMODEL_EXPORT QVariant CheckStateRole (const SessionItem &item)
 Returns check state role of given item. More...
 
MVVM_MODEL_EXPORT SessionItemChildAt (const SessionItem *parent, int index)
 Returns child at given index of parent. More...
 
MVVM_VIEW_EXPORT QString ClickableText (const QString &text, const QString &tag={})
 Returns text wrapped into 'href' tag to provide clickable links in QLabel. More...
 
MVVM_MODEL_EXPORT bool CompatibleVariantTypes (const Variant &oldValue, const Variant &newValue)
 Returns true if variants has compatible types. More...
 
template<typename A , typename B >
bool Contains (const A &container, const B &element)
 Returns true if container contains a given element. More...
 
MVVM_MODEL_EXPORT int CopyNumber (const SessionItem *item)
 Returns copy number of given item in it's parent hierarchy. More...
 
MVVM_MODEL_EXPORT bool create_directory (const std::string &path)
 Create directory, parent directory must exist. More...
 
template<typename T = SessionModel>
std::unique_ptr< T > CreateClone (const T &model)
 Creates exact clone of given model. All item's ID will be preserved. More...
 
template<typename T = SessionModel>
std::unique_ptr< T > CreateCopy (const T &model)
 Creates full deep copy of given model. All item's ID will be generated. More...
 
MVVM_VIEWMODEL_EXPORT QVariant DecorationRole (const SessionItem &item)
 Returns decoration role for given item. More...
 
MVVM_MODEL_EXPORT void DeleteItemFromModel (SessionItem *item)
 Removes and deletes item from its model. More...
 
MVVM_VIEW_EXPORT QStringList deserialize (const QByteArray &byteArray)
 Converts byte array to vector of strings. More...
 
MVVM_MODEL_EXPORT void EndMacros (const SessionItem *item)
 Finishes undo/redo macros. More...
 
MVVM_MODEL_EXPORT bool exists (const std::string &fileName)
 Returns true if file exists. More...
 
MVVM_MODEL_EXPORT std::vector< std::string > FindFiles (const std::string &dirname, const std::string &ext)
 Returns list of files with given extention found in given directory. More...
 
template<typename T = SessionItem>
std::vector< T * > FindItems (const SessionModel *model)
 Returns all items in a tree of given type. More...
 
MVVM_VIEW_EXPORT QMainWindow * FindMainWindow ()
 Finds main window. More...
 
MVVM_MODEL_EXPORT SessionItemFindNextItemToSelect (SessionItem *item)
 Finds next item to select Method is used in the context of next item selection after given item was deleted. More...
 
MVVM_MODEL_EXPORT SessionItemFindNextSibling (SessionItem *item)
 Returns next sibling with same tag. More...
 
MVVM_MODEL_EXPORT SessionItemFindPreviousSibling (SessionItem *item)
 Returns previous sibling with same tag. More...
 
MVVM_VIEW_EXPORT std::vector< std::string > fromStringList (const QStringList &string_list)
 Converts vector of strings to QStringList. More...
 
MVVM_MODEL_EXPORT bool HasTag (const SessionItem &item, const std::string &tag)
 Returns true if given item has registered tag. More...
 
MVVM_VIEW_EXPORT int HeightOfLetterM ()
 Returns height of the letter 'M' deduced from current font metrics. More...
 
template<typename C >
std::vector< double > Imag (const C &container)
 Returns vector with imag part of complex numbers. More...
 
MVVM_MODEL_EXPORT int IndexOfChild (const SessionItem *parent, const SessionItem *child)
 Returns index in children array corresponding to given child. More...
 
template<typename C , typename T >
int IndexOfItem (const C &container, const T &item)
 Returns index corresponding to the first occurance of the item in the container. More...
 
template<typename It , typename T >
int IndexOfItem (It begin, It end, const T &item)
 Returns index corresponding to the first occurance of the item in the container. More...
 
MVVM_MODEL_EXPORT bool is_empty (const std::string &path)
 Returns true if the file indicated by 'path' refers to empty file or directory. More...
 
MVVM_MODEL_EXPORT bool IsBoolVariant (const Variant &variant)
 Returns true in the case of double value based variant. More...
 
MVVM_MODEL_EXPORT bool IsColorVariant (const Variant &variant)
 Returns true in the case of QColor based variant. More...
 
MVVM_MODEL_EXPORT bool IsComboVariant (const Variant &variant)
 Returns true in the case of double value based variant. More...
 
MVVM_MODEL_EXPORT bool IsDoubleVariant (const Variant &variant)
 Returns true in the case of double value based variant. More...
 
MVVM_MODEL_EXPORT bool IsDoubleVectorVariant (const Variant &variant)
 Returns true in the case of variant based on std::vector<double>. More...
 
MVVM_MODEL_EXPORT bool IsExtPropertyVariant (const Variant &variant)
 Returns true in the case of ExternalProperty based variant. More...
 
MVVM_MODEL_EXPORT bool IsIntVariant (const Variant &variant)
 Returns true in the case of double value based variant. More...
 
MVVM_MODEL_EXPORT bool IsItemAncestor (const SessionItem *item, const SessionItem *candidate)
 Returns true if 'candidate' is one of ancestor of given item. More...
 
MVVM_VIEW_EXPORT bool IsLinuxHost ()
 Returns true if it is Linux. More...
 
MVVM_VIEW_EXPORT bool IsMacHost ()
 Returns true if it is Mac. More...
 
MVVM_MODEL_EXPORT bool IsRealLimitsVariant (const Variant &variant)
 Returns true in the case of RealLimits based variant. More...
 
MVVM_MODEL_EXPORT bool IsSinglePropertyTag (const SessionItem &item, const std::string &tag)
 Returns true if given item has registered tag, and it belongs to single property. More...
 
MVVM_MODEL_EXPORT bool IsStdStringVariant (const Variant &variant)
 Returns true in the case of double value based variant. More...
 
MVVM_MODEL_EXPORT bool IsTheSame (const Variant &var1, const Variant &var2)
 Returns true if given variants have same type and value. More...
 
MVVM_VIEW_EXPORT bool IsWindowsHost ()
 Returns true if it is Windows. More...
 
MVVM_MODEL_EXPORT SessionItemItemFromPath (const SessionModel &moodel, const Path &path)
 Returns item found in the model following given Path. More...
 
MVVM_VIEWMODEL_EXPORT QVector< int > ItemRoleToQtRole (int role)
 Returns vector of Qt roles corresponding to given ItemDataRole. More...
 
MVVM_VIEWMODEL_EXPORT std::vector< SessionItem * > ItemsFromIndex (const QModelIndexList &index_list)
 Returns vector of underlying SessionItem's for given index list. More...
 
MVVM_MODEL_EXPORT void iterate (SessionItem *item, const std::function< void(SessionItem *)> &fun)
 Iterates through item and all its children. More...
 
MVVM_MODEL_EXPORT void iterate_if (const SessionItem *item, const std::function< bool(const SessionItem *)> &fun)
 Iterates through all model indices and calls user function. More...
 
MVVM_VIEWMODEL_EXPORT void iterate_model (const QAbstractItemModel *model, const QModelIndex &parent, const std::function< void(const QModelIndex &child)> &fun)
 Iterates through QAbstractItem model. More...
 
MVVM_MODEL_EXPORT std::string join (const std::string &part1, const std::string &part2)
 Joins two path elements into the path. More...
 
MVVM_MODEL_EXPORT void MoveDown (SessionItem *item)
 Moves item down (increments row of the item). Works on children belonging to single tag. More...
 
MVVM_MODEL_EXPORT void MoveUp (SessionItem *item)
 Moves item up (decrements row of the item). Works on children belonging to single tag. More...
 
MVVM_MODEL_EXPORT std::string parent_path (const std::string &path)
 Returns the path to the parent directory. More...
 
MVVM_VIEWMODEL_EXPORT std::vector< SessionItem * > ParentItemsFromIndex (const QModelIndexList &index_list)
 Returns vector of parent items from given index list. More...
 
MVVM_MODEL_EXPORT Path PathFromItem (const SessionItem *item)
 Constructs path to find given item. Item must belong to a model. More...
 
MVVM_MODEL_EXPORT void PopulateEmptyModel (const JsonModelConverterInterface *converter, const SessionModel &source, SessionModel &target)
 Populate empty model with content of target model using provided converter. More...
 
MVVM_VIEW_EXPORT QString ProjectWindowTitle (const QString &project_dir, bool is_modified)
 Returns a title composed from last part of project path, and is_modified flag. More...
 
MVVM_MODEL_EXPORT double RandDouble (double low, double high)
 Produces random FLOAT values uniformly distributed on the interval [low, high). More...
 
MVVM_MODEL_EXPORT int RandInt (int low, int high)
 Produces random integer values uniformly distributed on the closed interval [low, high]. More...
 
MVVM_VIEW_EXPORT QColor RandomColor ()
 Returns random color. More...
 
MVVM_VIEW_EXPORT std::string RandomNamedColor ()
 Returns the name of random color. More...
 
template<typename C >
std::vector< double > Real (const C &container)
 Returns vector with real part of complex numbers. More...
 
MVVM_MODEL_EXPORT void Redo (SessionModel &model)
 Redo model operation which was undone just before. If not undo/redo enabled, will do nothing. More...
 
MVVM_MODEL_EXPORT std::vector< std::string > RegisteredTags (const SessionItem &item)
 Returns vector of strings containing all registered tags of the given item. More...
 
MVVM_MODEL_EXPORT std::vector< std::string > RegisteredUniversalTags (const SessionItem &item)
 Returns vector of strings containing all registered universal tags of the given item. More...
 
MVVM_MODEL_EXPORT bool remove (const std::string &path)
 Removes file or empty directory. More...
 
MVVM_MODEL_EXPORT void remove_all (const std::string &path)
 Removes directory with all its content. More...
 
MVVM_VIEW_EXPORT void ScaleLabelFont (QLabel *label, double scale)
 Set label's font size to system font size scaled by given factor. More...
 
MVVM_VIEW_EXPORT QByteArray serialize (const QStringList &data)
 Converts vector of strings to byte array. More...
 
MVVM_VIEW_EXPORT void SetLogarithmicScale (QCPAxis *axis, bool is_log_scale)
 Switch axis to logarithmic scale mode. More...
 
MVVM_VIEW_EXPORT void SetLogarithmicScale (QCPColorScale *axis, bool is_log_scale)
 Switch axis to logarithmic scale mode. More...
 
MVVM_MODEL_EXPORT std::vector< SessionItem * > SinglePropertyItems (const SessionItem &item)
 Returns vector of children representing property items. More...
 
MVVM_VIEW_EXPORT QSize SizeOfLetterM ()
 Returns size corresponding to actual size of letter M basing on current font metrics. More...
 
MVVM_VIEW_EXPORT int SystemPointSize ()
 Returns size in points of default system font. More...
 
MVVM_VIEWMODEL_EXPORT QVariant TextColorRole (const SessionItem &item)
 Returns text color for given item. More...
 
MVVM_MODEL_EXPORT Variant toCustomVariant (const Variant &standard)
 Converts Qt variant to custom variant on board of SessionItem. More...
 
MVVM_VIEWMODEL_EXPORT QVariant ToolTipRole (const SessionItem &item)
 Returns tooltip role for given item. More...
 
template<typename T = SessionItem>
T * TopItem (const SessionModel *model)
 Returns top level item of given type. More...
 
template<typename T = SessionItem>
std::vector< T * > TopItems (const SessionModel *model)
 Returns all top level items of given type. More...
 
MVVM_MODEL_EXPORT std::vector< SessionItem * > TopLevelItems (const SessionItem &item)
 Returns vector of children representing top level items. More...
 
MVVM_MODEL_EXPORT Variant toQtVariant (const Variant &custom)
 Converts custom variant to standard variant which Qt views will understand. More...
 
MVVM_VIEW_EXPORT QStringList toStringList (const std::vector< std::string > &vec)
 Converts vector of strings to QStringList. More...
 
MVVM_MODEL_EXPORT void Undo (SessionModel &model)
 Undo last model operation. If not undo/redo enabled, will do nothing. More...
 
MVVM_MODEL_EXPORT std::vector< SessionItem * > UniqueItems (const std::vector< SessionItem * > &items)
 Returns vector with duplicates and 'nullptr' filtered out. More...
 
MVVM_VIEWMODEL_EXPORT std::vector< SessionItem * > UniqueItemsFromIndex (const QModelIndexList &index_list)
 Returns vector of underlying SessionItem's for given index list. Removes repetitions. More...
 
template<typename C >
UniqueWithOrder (const C &container)
 Returns copy of container with all duplicated elements filtered our. The order is preserved. More...
 
MVVM_MODEL_EXPORT std::string VariantName (const Variant &variant)
 Returns name of variant. More...
 
MVVM_MODEL_EXPORT int VariantType (const Variant &variant)
 Returns type of variant (additionally checks for user type). More...
 
MVVM_VIEW_EXPORT int WidthOfLetterM ()
 Returns width of the letter 'M' deduced from current font metrics. More...
 
MVVM_VIEW_EXPORT QString WithTildeHomePath (const QString &path)
 Returns a string where Linux path to the file is striped using '~/'. More...
 

Detailed Description

Collection of various widget-related utils.

Function Documentation

◆ Apply()

template<typename It , typename UnaryFunction >
std::vector<double> ModelView::Utils::Apply ( It  begin,
It  end,
UnaryFunction  func 
)

Returns vector containing results of elemntwise unary function application.

Definition at line 63 of file containerutils.h.

64 {
65  std::vector<double> result;
66  std::transform(begin, end, std::back_inserter(result), func);
67  return result;
68 }

Referenced by Imag(), and Real().

◆ AreAlmostEqual()

bool ModelView::Utils::AreAlmostEqual ( double  a,
double  b,
double  tolerance_factor = 1.0 
)

Returns true if two doubles agree within epsilon*tolerance.

Definition at line 23 of file numericutils.cpp.

24 {
25  constexpr double eps = std::numeric_limits<double>::epsilon();
26  return std::abs(a - b)
27  <= eps * std::max(tolerance * eps, std::max(1., tolerance) * std::abs(b));
28 }

Referenced by ModelView::DoubleEditor::onEditingFinished(), ModelView::ScientificDoubleEditor::onEditingFinished(), ModelView::ScientificSpinBoxEditor::onEditingFinished(), and TEST_F().

◆ base_name()

std::string ModelView::Utils::base_name ( const std::string &  path)

Provide the filename of a file path.

Definition at line 78 of file fileutils.cpp.

79 {
80 #ifdef ENABLE_FILESYSTEM
81  return std::filesystem::path(path).stem().string();
82 #else
83  return QFileInfo(QString::fromStdString(path)).completeBaseName().toStdString();
84 #endif
85 }

Referenced by IParametricComponent::registerVector(), IParametricComponent::removeVector(), IParametricComponent::setVectorValue(), TEST_F(), IParametricComponent::XComponentName(), IParametricComponent::YComponentName(), and IParametricComponent::ZComponentName().

◆ BeginMacros()

void ModelView::Utils::BeginMacros ( const SessionItem item,
const std::string &  macro_name 
)

Begin undo/redo macros with given name.

Works only if item belongs to the model, and model has undo/redo enabled. Otherwise, do nothing.

Definition at line 91 of file modelutils.cpp.

92 {
93  if (!item->model())
94  return;
95 
96  if (auto stack = item->model()->undoStack(); stack)
97  stack->beginMacro(macro_name);
98 }
SessionModel * model() const
Returns the model to which given item belongs to.
UndoStackInterface * undoStack() const
Returns command stack to perform undo/redo.

References ModelView::SessionItem::model(), and ModelView::SessionModel::undoStack().

Referenced by ModelView::ViewportItem::setViewportToContent().

Here is the call graph for this function:

◆ CastedItems()

template<typename T >
std::vector<T*> ModelView::Utils::CastedItems ( const std::vector< SessionItem * > &  items)

Returns vector of items casted to given type.

Definition at line 90 of file itemutils.h.

91 {
92  std::vector<T*> result;
93  for (auto item : items)
94  if (auto casted_item = dynamic_cast<T*>(item); casted_item)
95  result.push_back(casted_item);
96 
97  return result;
98 }

◆ CheckStateRole()

QVariant ModelView::Utils::CheckStateRole ( const SessionItem item)

Returns check state role of given item.

Definition at line 73 of file viewmodelutils.cpp.

74 {
75  auto value = item.data<QVariant>();
76  if (Utils::IsBoolVariant(value))
77  return value.value<bool>() ? Qt::Checked : Qt::Unchecked;
78  return QVariant();
79 }
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148
MVVM_MODEL_EXPORT bool IsBoolVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::SessionItem::data(), and IsBoolVariant().

Referenced by ModelView::ViewDataItem::data(), and TEST_F().

Here is the call graph for this function:

◆ ChildAt()

SessionItem * ModelView::Utils::ChildAt ( const SessionItem parent,
int  index 
)

Returns child at given index of parent.

No tags are involved, index is considered as global index in the combined array of all children.

Definition at line 70 of file itemutils.cpp.

71 {
72  if (!parent)
73  return nullptr;
74 
75  auto container = parent->children();
76  return index >= 0 && static_cast<size_t>(index) < container.size()
77  ? container[static_cast<size_t>(index)]
78  : nullptr;
79 }
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.

References ModelView::SessionItem::children().

Referenced by ItemFromPath(), and TEST_F().

Here is the call graph for this function:

◆ ClickableText()

QString ModelView::Utils::ClickableText ( const QString &  text,
const QString &  tag = {} 
)

Returns text wrapped into 'href' tag to provide clickable links in QLabel.

Example: text, if 'tag' is empty, 'text' will be used instead.

Definition at line 136 of file widgetutils.cpp.

137 {
138  return QString("<a href=\"%1\">%2</a>").arg(tag.isEmpty() ? text : tag, text);
139 }

Referenced by gui2::OpenProjectWidget::createLinkedLabelLayout(), and TEST_F().

◆ CompatibleVariantTypes()

bool ModelView::Utils::CompatibleVariantTypes ( const Variant oldValue,
const Variant newValue 
)

Returns true if variants has compatible types.

Definition at line 39 of file customvariants.cpp.

40 {
41  // Invalid variant can be rewritten by any variant.
42  // Valid Variant can be replaced by invalid variant.
43  // In other cases types of variants should coincide to be compatible.
44 
45  if (!oldValue.isValid() || !newValue.isValid())
46  return true;
47 
48  return Utils::VariantType(oldValue) == Utils::VariantType(newValue);
49 }
int VariantType(const QVariant &variant)
Returns type of variant (additionally checks for user type).

References VariantType().

Referenced by ModelView::SessionItemData::assure_validity(), and TEST_F().

Here is the call graph for this function:

◆ Contains()

template<typename A , typename B >
bool ModelView::Utils::Contains ( const A &  container,
const B &  element 
)

Returns true if container contains a given element.

Definition at line 103 of file containerutils.h.

104 {
105  return std::find(container.begin(), container.end(), element) != container.end();
106 }

Referenced by ModelView::TagInfo::isValidChild(), ModelView::ComboProperty::setStringOfValues(), ModelView::ComboProperty::setValue(), ModelView::ComboProperty::setValues(), TEST_F(), ModelView::SelectableComboBoxEditor::update_components(), and gui2::DataHandler::updateRawData().

◆ CopyNumber()

int ModelView::Utils::CopyNumber ( const SessionItem item)

Returns copy number of given item in it's parent hierarchy.

Takes into account only items with same modelType.

Definition at line 49 of file itemutils.cpp.

50 {
51  int result(-1);
52 
53  if (!item)
54  return result;
55 
56  int count(0);
57  auto model_type = item->modelType();
58  if (auto parent = item->parent()) {
59  for (auto child : parent->children()) {
60  if (child == item)
61  result = count;
62  if (child->modelType() == model_type)
63  ++count;
64  }
65  }
66 
67  return count > 1 ? result : -1;
68 }
SessionItem * parent() const
Returns parent item. Will return nullptr if item doesn't have a parent.
model_type modelType() const
Returns item's model type.
Definition: sessionitem.cpp:80
std::string model_type
Definition: types.h:23

References ModelView::SessionItem::modelType(), and ModelView::SessionItem::parent().

Referenced by ModelView::CompoundItem::displayName(), and TEST_F().

Here is the call graph for this function:

◆ create_directory()

bool ModelView::Utils::create_directory ( const std::string &  path)

Create directory, parent directory must exist.

If path resolves to existing directory, no error reported.

Definition at line 47 of file fileutils.cpp.

48 {
49 #ifdef ENABLE_FILESYSTEM
51 #else
52  QDir dir(QString::fromStdString(path));
53  return dir.mkpath(".");
54 #endif
55 }
MVVM_MODEL_EXPORT bool create_directory(const std::string &path)
Create directory, parent directory must exist.
Definition: fileutils.cpp:47

Referenced by FileSystemUtils::createDirectory(), FolderBasedTest::createEmptyDir(), TestUtils::CreateTestDirectory(), and TEST_F().

◆ CreateClone()

template<typename T = SessionModel>
std::unique_ptr<T> ModelView::Utils::CreateClone ( const T &  model)

Creates exact clone of given model. All item's ID will be preserved.

Definition at line 90 of file modelutils.h.

91 {
92  auto result = std::make_unique<T>();
93  auto converter = CreateModelCloneConverter();
94  PopulateEmptyModel(converter.get(), model, *result.get());
95  return result;
96 }
MVVM_MODEL_EXPORT void PopulateEmptyModel(const JsonModelConverterInterface *converter, const SessionModel &source, SessionModel &target)
Populate empty model with content of target model using provided converter.
Definition: modelutils.cpp:47
MVVM_MODEL_EXPORT std::unique_ptr< JsonModelConverterInterface > CreateModelCloneConverter()
Creates a JSON model converter intended for model cloning.

References ModelView::CreateModelCloneConverter(), and PopulateEmptyModel().

Referenced by TEST_F().

Here is the call graph for this function:

◆ CreateCopy()

template<typename T = SessionModel>
std::unique_ptr<T> ModelView::Utils::CreateCopy ( const T &  model)

Creates full deep copy of given model. All item's ID will be generated.

Definition at line 81 of file modelutils.h.

82 {
83  auto result = std::make_unique<T>();
84  auto converter = CreateModelCopyConverter();
85  PopulateEmptyModel(converter.get(), model, *result.get());
86  return result;
87 }
MVVM_MODEL_EXPORT std::unique_ptr< JsonModelConverterInterface > CreateModelCopyConverter()
Creates a JSON model converter intended for model copying.

References ModelView::CreateModelCopyConverter(), and PopulateEmptyModel().

Referenced by TEST_F().

Here is the call graph for this function:

◆ DecorationRole()

QVariant ModelView::Utils::DecorationRole ( const SessionItem item)

Returns decoration role for given item.

Definition at line 81 of file viewmodelutils.cpp.

82 {
83  auto value = item.data<QVariant>();
84  if (Utils::IsColorVariant(value))
85  return value;
86  else if (Utils::IsExtPropertyVariant(value))
87  return value.value<ExternalProperty>().color();
88  return QVariant();
89 }
Property to carry text, color and identifier.
MVVM_MODEL_EXPORT bool IsColorVariant(const Variant &variant)
Returns true in the case of QColor based variant.
MVVM_MODEL_EXPORT bool IsExtPropertyVariant(const Variant &variant)
Returns true in the case of ExternalProperty based variant.

References ModelView::ExternalProperty::color(), ModelView::SessionItem::data(), IsColorVariant(), and IsExtPropertyVariant().

Referenced by ModelView::ViewDataItem::data(), and TEST_F().

Here is the call graph for this function:

◆ DeleteItemFromModel()

void ModelView::Utils::DeleteItemFromModel ( SessionItem item)

Removes and deletes item from its model.

Definition at line 54 of file modelutils.cpp.

55 {
56  auto model = item->model();
57  if (!model)
58  return;
59 
60  model->removeItem(item->parent(), item->tagRow());
61 }
TagRow tagRow() const
Returns TagRow of this item under which it is accessible through its parent.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.

References ModelView::SessionItem::model(), ModelView::SessionItem::parent(), ModelView::SessionModel::removeItem(), and ModelView::SessionItem::tagRow().

Referenced by gui2::LayerEditorActions::onRemove(), gui2::MaterialEditorActions::onRemoveMaterial(), gui2::JobItem::removeDifferenceGraph(), gui2::JobItem::removeReferenceGraph(), and TEST_F().

Here is the call graph for this function:

◆ deserialize()

QStringList ModelView::Utils::deserialize ( const QByteArray &  byteArray)

Converts byte array to vector of strings.

Definition at line 172 of file widgetutils.cpp.

173 {
174  QByteArray array = byteArray;
175  QStringList result;
176  QDataStream in(&array, QIODevice::ReadOnly);
177  in >> result;
178  return result;
179 }

Referenced by gui2::DataViewModel::dropMimeData(), and TEST_F().

◆ EndMacros()

void ModelView::Utils::EndMacros ( const SessionItem item)

Finishes undo/redo macros.

Works only if item belongs to the model, and model has undo/redo enabled. Otherwise, do nothing.

Definition at line 100 of file modelutils.cpp.

101 {
102  if (!item->model())
103  return;
104 
105  if (auto stack = item->model()->undoStack(); stack)
106  stack->endMacro();
107 }

References ModelView::SessionItem::model(), and ModelView::SessionModel::undoStack().

Referenced by ModelView::ViewportItem::setViewportToContent().

Here is the call graph for this function:

◆ exists()

bool ModelView::Utils::exists ( const std::string &  fileName)

Returns true if file exists.

Definition at line 27 of file fileutils.cpp.

28 {
29 #ifdef ENABLE_FILESYSTEM
30  return std::filesystem::exists(fileName);
31 #else
32  QFileInfo info(QString::fromStdString(fileName));
33  return info.exists();
34 #endif
35 }
bool exists(const QString &fileName)
Returns true if file exists.

References ProjectUtils::exists().

Referenced by ModelView::Project::ProjectImpl::process(), gui2::RecentProjectSettings::recentProjects(), and TEST_F().

Here is the call graph for this function:

◆ FindFiles()

std::vector< std::string > ModelView::Utils::FindFiles ( const std::string &  dirname,
const std::string &  ext 
)

Returns list of files with given extention found in given directory.

Definition at line 87 of file fileutils.cpp.

88 {
89 #ifdef ENABLE_FILESYSTEM
90  std::vector<std::string> result;
91  for (const auto& entry : std::filesystem::directory_iterator(dirname)) {
92  const auto filenameStr = entry.path().filename().string();
93  if (entry.is_regular_file() && entry.path().extension() == ext)
94  result.push_back(entry.path().string());
95  }
96  return result;
97 #else
98  std::vector<std::string> result;
99  QDir dir(QString::fromStdString(dirname));
100  if (dir.exists()) {
101  QStringList filters = {QString::fromStdString("*" + ext)};
102  for (auto entry : dir.entryList(filters)) {
103  auto name = dir.filePath(entry);
104  result.push_back(name.toStdString());
105  }
106  }
107  return result;
108 #endif
109 }
QString const & name(EShape k)
Definition: particles.cpp:21

References RealSpace::Particles::name().

Referenced by ModelView::ProjectUtils::IsPossibleProjectDir(), and TEST_F().

Here is the call graph for this function:

◆ FindItems()

template<typename T = SessionItem>
std::vector<T*> ModelView::Utils::FindItems ( const SessionModel model)

Returns all items in a tree of given type.

Definition at line 55 of file modelutils.h.

56 {
57  std::vector<T*> result;
58 
59  auto func = [&result](SessionItem* item) {
60  if (auto concrete = dynamic_cast<T*>(item); concrete)
61  result.push_back(concrete);
62  };
63 
64  iterate(model->rootItem(), func);
65 
66  return result;
67 }
SessionItem * rootItem() const
void iterate(const QModelIndex &index, const QAbstractItemModel *model, const std::function< void(const QModelIndex &)> &fun)
Iterates through all model indices and calls user function.
Definition: ModelUtils.cpp:33

References iterate(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ FindMainWindow()

QMainWindow * ModelView::Utils::FindMainWindow ( )

Finds main window.

Definition at line 127 of file widgetutils.cpp.

128 {
129  for (auto widget : qApp->topLevelWidgets()) {
130  if (auto result = dynamic_cast<QMainWindow*>(widget); result)
131  return result;
132  }
133  return nullptr;
134 }

Referenced by gui2::ProjectHandler::updateCurrentProjectName().

◆ FindNextItemToSelect()

SessionItem * ModelView::Utils::FindNextItemToSelect ( SessionItem item)

Finds next item to select Method is used in the context of next item selection after given item was deleted.

Definition at line 149 of file itemutils.cpp.

150 {
151  auto next = FindNextSibling(item);
152  auto closest = next ? next : FindPreviousSibling(item);
153  return closest ? closest : item->parent();
154 }
MVVM_MODEL_EXPORT SessionItem * FindNextSibling(SessionItem *item)
Returns next sibling with same tag.
Definition: itemutils.cpp:131
MVVM_MODEL_EXPORT SessionItem * FindPreviousSibling(SessionItem *item)
Returns previous sibling with same tag.
Definition: itemutils.cpp:140

References FindNextSibling(), FindPreviousSibling(), and ModelView::SessionItem::parent().

Referenced by TEST_F().

Here is the call graph for this function:

◆ FindNextSibling()

SessionItem * ModelView::Utils::FindNextSibling ( SessionItem item)

Returns next sibling with same tag.

Definition at line 131 of file itemutils.cpp.

132 {
133  auto parent = item ? item->parent() : nullptr;
134  if (!parent)
135  return nullptr;
136  auto tagrow = item->tagRow();
137  return parent->getItem(tagrow.tag, tagrow.row + 1);
138 }

References ModelView::SessionItem::parent(), and ModelView::SessionItem::tagRow().

Referenced by FindNextItemToSelect(), gui2::LayerEditorActions::onRemove(), and TEST_F().

Here is the call graph for this function:

◆ FindPreviousSibling()

SessionItem * ModelView::Utils::FindPreviousSibling ( SessionItem item)

Returns previous sibling with same tag.

Definition at line 140 of file itemutils.cpp.

141 {
142  auto parent = item ? item->parent() : nullptr;
143  if (!parent)
144  return nullptr;
145  auto tagrow = parent->tagRowOfItem(item);
146  return parent->getItem(tagrow.tag, tagrow.row - 1);
147 }
TagRow tagRowOfItem(const SessionItem *item) const
Returns pair of tag and row corresponding to given item.

References ModelView::SessionItem::parent(), and ModelView::SessionItem::tagRowOfItem().

Referenced by FindNextItemToSelect(), gui2::LayerEditorActions::onRemove(), and TEST_F().

Here is the call graph for this function:

◆ fromStringList()

std::vector< std::string > ModelView::Utils::fromStringList ( const QStringList &  string_list)

Converts vector of strings to QStringList.

Definition at line 156 of file widgetutils.cpp.

157 {
158  std::vector<std::string> result;
159  for (const auto& x : string_list)
160  result.push_back(x.toStdString());
161  return result;
162 }

Referenced by gui2::DataLoaderDialog::onLoadFilesRequest(), and TEST_F().

◆ HasTag()

bool ModelView::Utils::HasTag ( const SessionItem item,
const std::string &  tag 
)

Returns true if given item has registered tag.

Definition at line 86 of file itemutils.cpp.

87 {
88  return item.itemTags()->isTag(tag);
89 }
bool isTag(const std::string &name) const
Returns true if container with such name exists.
SessionItemTags * itemTags()
Returns pointer to internal collection of tag-registered items (non-const version).

References ModelView::SessionItemTags::isTag(), and ModelView::SessionItem::itemTags().

Referenced by gui2::MaterialBaseItem::external_property(), and TEST_F().

Here is the call graph for this function:

◆ HeightOfLetterM()

int ModelView::Utils::HeightOfLetterM ( )

Returns height of the letter 'M' deduced from current font metrics.

Definition at line 111 of file widgetutils.cpp.

112 {
113  return ModelView::Utils::SizeOfLetterM().height();
114 }
MVVM_VIEW_EXPORT QSize SizeOfLetterM()
Returns size corresponding to actual size of letter M basing on current font metrics.

References SizeOfLetterM().

Referenced by ModelView::CollapsibleBar::CollapsibleBar(), and gui2::FancyTab::FancyTab().

Here is the call graph for this function:

◆ Imag()

template<typename C >
std::vector<double> ModelView::Utils::Imag ( const C &  container)

Returns vector with imag part of complex numbers.

Definition at line 80 of file containerutils.h.

81 {
82  return Apply(std::begin(container), std::end(container),
83  [](const auto& x) { return std::imag(x); });
84 }
std::vector< double > Apply(It begin, It end, UnaryFunction func)
Returns vector containing results of elemntwise unary function application.

References Apply().

Referenced by TEST_F().

Here is the call graph for this function:

◆ IndexOfChild()

int ModelView::Utils::IndexOfChild ( const SessionItem parent,
const SessionItem child 
)

Returns index in children array corresponding to given child.

No tags are involved, index is considered as global index in the combined array of all children.

Definition at line 81 of file itemutils.cpp.

82 {
83  return Utils::IndexOfItem(parent->children(), child);
84 }
int IndexOfItem(It begin, It end, const T &item)
Returns index corresponding to the first occurance of the item in the container.

References ModelView::SessionItem::children(), and IndexOfItem().

Referenced by PathFromItem(), and TEST_F().

Here is the call graph for this function:

◆ IndexOfItem() [1/2]

template<typename C , typename T >
int ModelView::Utils::IndexOfItem ( const C &  container,
const T &  item 
)

Returns index corresponding to the first occurance of the item in the container.

If item doesn't exist, will return -1. Works with containers containing unique_ptr.

Definition at line 55 of file containerutils.h.

56 {
57  return IndexOfItem(container.begin(), container.end(), item);
58 }
int IndexOfItem(const C &container, const T &item)
Returns index corresponding to the first occurance of the item in the container.

References IndexOfItem().

Here is the call graph for this function:

◆ IndexOfItem() [2/2]

template<typename It , typename T >
int ModelView::Utils::IndexOfItem ( It  begin,
It  end,
const T &  item 
)

Returns index corresponding to the first occurance of the item in the container.

If item doesn't exist, will return -1. Works with containers containing unique_ptr.

Definition at line 41 of file containerutils.h.

42 {
43  It pos;
44  if constexpr (is_unique_ptr<typename std::iterator_traits<It>::value_type>::value)
45  pos = find_if(begin, end, [&item](const auto& x) { return x.get() == item; });
46  else
47  pos = find_if(begin, end, [&item](const auto& x) { return x == item; });
48 
49  return pos == end ? -1 : static_cast<int>(std::distance(begin, pos));
50 }

Referenced by gui2::ImportDataEditor::canvasInfo(), ModelView::ViewItem::ViewItemImpl::index_of_child(), IndexOfChild(), IndexOfItem(), ModelView::SessionItemContainer::indexOfItem(), ModelView::ViewModelController::ViewModelControllerImpl::insert_view(), ModelView::GroupItem::setCurrentType(), ModelView::ComboProperty::setSelected(), ModelView::ComboProperty::setStringOfValues(), ModelView::ComboProperty::setValue(), ModelView::ComboProperty::setValues(), and TEST_F().

◆ is_empty()

bool ModelView::Utils::is_empty ( const std::string &  path)

Returns true if the file indicated by 'path' refers to empty file or directory.

Definition at line 121 of file fileutils.cpp.

122 {
123 #ifdef ENABLE_FILESYSTEM
124  return std::filesystem::is_empty(path);
125 #else
126  QFileInfo info(QString::fromStdString(path));
127  if (info.isDir()) {
128  QDir dir(QString::fromStdString(path));
129  return dir.isEmpty();
130  } else {
131  return info.size() == 0;
132  }
133  return false;
134 #endif
135 }
MVVM_MODEL_EXPORT bool is_empty(const std::string &path)
Returns true if the file indicated by 'path' refers to empty file or directory.
Definition: fileutils.cpp:121

Referenced by ModelView ::Compatibility::IsCompatibleUniversalTag(), gui2::UserInteractor::onCreateDirRequest(), and TEST_F().

◆ IsBoolVariant()

bool ModelView::Utils::IsBoolVariant ( const Variant variant)

Returns true in the case of double value based variant.

Definition at line 92 of file customvariants.cpp.

93 {
94  return variant.type() == Variant::Bool;
95 }

Referenced by ModelView::DefaultCellDecorator::cellText(), CheckStateRole(), and TEST_F().

◆ IsColorVariant()

bool ModelView::Utils::IsColorVariant ( const Variant variant)

Returns true in the case of QColor based variant.

Definition at line 122 of file customvariants.cpp.

123 {
124  return variant.type() == Variant::Color;
125 }

Referenced by ModelView::DefaultCellDecorator::cellText(), DecorationRole(), TEST_F(), and ModelView::ColorEditor::update_components().

◆ IsComboVariant()

bool ModelView::Utils::IsComboVariant ( const Variant variant)

Returns true in the case of double value based variant.

Definition at line 107 of file customvariants.cpp.

108 {
109  return variant.canConvert<ComboProperty>();
110 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27

Referenced by ModelView::DefaultCellDecorator::cellText(), and TEST_F().

◆ IsDoubleVariant()

bool ModelView::Utils::IsDoubleVariant ( const Variant variant)

Returns true in the case of double value based variant.

Definition at line 102 of file customvariants.cpp.

103 {
104  return variant.type() == Variant::Double;
105 }

Referenced by ModelView::DefaultCellDecorator::cellText(), and TEST_F().

◆ IsDoubleVectorVariant()

bool ModelView::Utils::IsDoubleVectorVariant ( const Variant variant)

Returns true in the case of variant based on std::vector<double>.

Definition at line 117 of file customvariants.cpp.

118 {
119  return variant.typeName() == Constants::vector_double_type_name;
120 }
const std::string vector_double_type_name

References ModelView::Constants::vector_double_type_name.

Referenced by TEST_F(), and toQtVariant().

◆ IsExtPropertyVariant()

bool ModelView::Utils::IsExtPropertyVariant ( const Variant variant)

◆ IsIntVariant()

bool ModelView::Utils::IsIntVariant ( const Variant variant)

Returns true in the case of double value based variant.

Definition at line 97 of file customvariants.cpp.

98 {
99  return variant.type() == Variant::Int;
100 }

Referenced by TEST_F().

◆ IsItemAncestor()

bool ModelView::Utils::IsItemAncestor ( const SessionItem item,
const SessionItem candidate 
)

Returns true if 'candidate' is one of ancestor of given item.

Definition at line 156 of file itemutils.cpp.

157 {
158  if (!item || !candidate)
159  return false;
160  const SessionItem* parent = item->parent();
161  while (parent) {
162  if (parent == candidate)
163  return true;
164  else
165  parent = parent->parent();
166  }
167  return false;
168 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38

References ModelView::SessionItem::parent().

Referenced by ModelView::ViewModelController::onAboutToRemoveItem(), and TEST_F().

Here is the call graph for this function:

◆ IsLinuxHost()

bool ModelView::Utils::IsLinuxHost ( )

Returns true if it is Linux.

Definition at line 70 of file widgetutils.cpp.

71 {
72 #if defined(Q_OS_LINUX)
73  return true;
74 #else
75  return false;
76 #endif
77 }

◆ IsMacHost()

bool ModelView::Utils::IsMacHost ( )

Returns true if it is Mac.

Definition at line 61 of file widgetutils.cpp.

62 {
63 #if defined(Q_OS_MAC)
64  return true;
65 #else
66  return false;
67 #endif
68 }

◆ IsRealLimitsVariant()

bool ModelView::Utils::IsRealLimitsVariant ( const Variant variant)

Returns true in the case of RealLimits based variant.

Definition at line 132 of file customvariants.cpp.

133 {
134  return variant.canConvert<RealLimits>();
135 }
Limits for double.
Definition: reallimits.h:25

Referenced by TEST_F().

◆ IsSinglePropertyTag()

bool ModelView::Utils::IsSinglePropertyTag ( const SessionItem item,
const std::string &  tag 
)

Returns true if given item has registered tag, and it belongs to single property.

Definition at line 91 of file itemutils.cpp.

92 {
93  return item.itemTags()->isSinglePropertyTag(tag);
94 }
bool isSinglePropertyTag(const std::string &tag) const
Returns true if given tag corresponds to registered single property tag.

References ModelView::SessionItemTags::isSinglePropertyTag(), and ModelView::SessionItem::itemTags().

Referenced by ModelView::MoveItemCommand::MoveItemCommand(), RegisteredUniversalTags(), SinglePropertyItems(), TEST_F(), and TopLevelItems().

Here is the call graph for this function:

◆ IsStdStringVariant()

bool ModelView::Utils::IsStdStringVariant ( const Variant variant)

Returns true in the case of double value based variant.

Definition at line 112 of file customvariants.cpp.

113 {
114  return variant.canConvert<std::string>();
115 }

Referenced by TEST_F().

◆ IsTheSame()

bool ModelView::Utils::IsTheSame ( const Variant var1,
const Variant var2 
)

Returns true if given variants have same type and value.

Definition at line 51 of file customvariants.cpp.

52 {
53  // variants of different type are always reported as not the same
54  if (VariantType(var1) != VariantType(var2))
55  return false;
56 
57  // variants of same type are compared by value
58  return var1 == var2;
59 }

References SessionItemUtils::VariantType().

Referenced by ModelView::DataRole::operator==(), ModelView::SessionItemData::setData(), and TEST_F().

Here is the call graph for this function:

◆ IsWindowsHost()

bool ModelView::Utils::IsWindowsHost ( )

Returns true if it is Windows.

Definition at line 52 of file widgetutils.cpp.

53 {
54 #if defined(Q_OS_WIN)
55  return true;
56 #else
57  return false;
58 #endif
59 }

Referenced by TEST_F(), and WithTildeHomePath().

◆ ItemFromPath()

SessionItem * ModelView::Utils::ItemFromPath ( const SessionModel moodel,
const Path path 
)

Returns item found in the model following given Path.

Definition at line 36 of file modelutils.cpp.

37 {
38  SessionItem* result(model.rootItem());
39  for (const auto& x : path) {
40  result = Utils::ChildAt(result, x);
41  if (!result)
42  break;
43  }
44  return result;
45 }
MVVM_MODEL_EXPORT SessionItem * ChildAt(const SessionItem *parent, int index)
Returns child at given index of parent.
Definition: itemutils.cpp:70

References ChildAt(), and ModelView::SessionModel::rootItem().

Referenced by ModelView::ViewModelController::ViewModelController(), ModelView::AbstractItemCommand::itemFromPath(), and TEST_F().

Here is the call graph for this function:

◆ ItemRoleToQtRole()

QVector< int > ModelView::Utils::ItemRoleToQtRole ( int  role)

Returns vector of Qt roles corresponding to given ItemDataRole.

Translates SessionItem's data role to vector of Qt roles.

Definition at line 50 of file viewmodelutils.cpp.

51 {
52  QVector<int> result;
53  // In Qt when we are editing the data in a view two roles are emmited.
54  if (role == ItemDataRole::DISPLAY || role == ItemDataRole::DATA)
55  result = {Qt::DisplayRole, Qt::EditRole};
56  else if (role == ItemDataRole::APPEARANCE)
57 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
58  result = {Qt::ForegroundRole};
59 #else
60  result = {Qt::TextColorRole};
61 #endif
62  else if (role == ItemDataRole::TOOLTIP)
63  result = {Qt::ToolTipRole};
64 
65  return result;
66 }
const int TOOLTIP
tooltip for item's data
Definition: mvvm_types.h:34
const int DATA
main data role
Definition: mvvm_types.h:30
const int APPEARANCE
appearance flag
Definition: mvvm_types.h:32
const int DISPLAY
display name
Definition: mvvm_types.h:31
MVVM_VIEWMODEL_EXPORT QVariant TextColorRole(const SessionItem &item)
Returns text color for given item.
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.
QVariant ForegroundRole(const SessionItem &item)
Returns text color for given item.

References ModelView::ItemDataRole::APPEARANCE, ModelView::ItemDataRole::DATA, ModelView::ItemDataRole::DISPLAY, SessionItemUtils::ForegroundRole(), TextColorRole(), ModelView::ItemDataRole::TOOLTIP, and SessionItemUtils::ToolTipRole().

Referenced by ModelView::ViewModelController::onDataChange(), and TEST_F().

Here is the call graph for this function:

◆ ItemsFromIndex()

std::vector< SessionItem * > ModelView::Utils::ItemsFromIndex ( const QModelIndexList &  index_list)

Returns vector of underlying SessionItem's for given index list.

Definition at line 97 of file viewmodelutils.cpp.

98 {
99  if (index_list.empty())
100  return {};
101 
102  std::vector<SessionItem*> result;
103 
104  if (auto model = dynamic_cast<const ViewModelBase*>(index_list.front().model()))
105  std::transform(index_list.begin(), index_list.end(), std::back_inserter(result),
106  [model](auto index) { return model->itemFromIndex(index)->item(); });
107 
108  return result;
109 }
Base class for all view models to show content of SessionModel in Qt views.
Definition: viewmodelbase.h:31

Referenced by ParentItemsFromIndex(), gui2::DataSelectionModel::selectedItems(), TEST_F(), and UniqueItemsFromIndex().

◆ iterate()

void ModelView::Utils::iterate ( SessionItem item,
const std::function< void(SessionItem *)> &  fun 
)

Iterates through item and all its children.

Definition at line 24 of file itemutils.cpp.

25 {
26  if (item)
27  fun(item);
28  else
29  return;
30 
31  for (auto child : item->children())
32  iterate(child, fun);
33 }

References ModelView::SessionItem::children(), and ModelUtils::iterate().

Referenced by FindItems(), and TEST_F().

Here is the call graph for this function:

◆ iterate_if()

void ModelView::Utils::iterate_if ( const SessionItem item,
const std::function< bool(const SessionItem *)> &  fun 
)

Iterates through all model indices and calls user function.

If function returns false for given index, iteration will not go down to children.

Definition at line 35 of file itemutils.cpp.

36 {
37  bool proceed_with_children(true);
38 
39  if (item)
40  proceed_with_children = fun(item);
41 
42  if (!item || !proceed_with_children)
43  return;
44 
45  for (auto child : item->children())
46  iterate_if(child, fun);
47 }
void iterate_if(const QModelIndex &index, const QAbstractItemModel *model, const std::function< bool(const QModelIndex &)> &fun)
Iterates through all model indices and calls user function.
Definition: ModelUtils.cpp:47

References ModelView::SessionItem::children(), and ModelUtils::iterate_if().

Referenced by TEST_F().

Here is the call graph for this function:

◆ iterate_model()

void ModelView::Utils::iterate_model ( const QAbstractItemModel *  model,
const QModelIndex &  parent,
const std::function< void(const QModelIndex &child)> &  fun 
)

Iterates through QAbstractItem model.

Definition at line 29 of file viewmodelutils.cpp.

31 {
32  if (!model)
33  return;
34 
35  for (int row = 0; row < model->rowCount(parent); ++row) {
36  for (int col = 0; col < model->columnCount(parent); ++col) {
37  auto index = model->index(row, col, parent);
38  if (index.isValid())
39  fun(index);
40  }
41  for (int col = 0; col < model->columnCount(parent); ++col) {
42  auto index = model->index(row, col, parent);
43  iterate_model(model, index, fun);
44  }
45  }
46 }
MVVM_VIEWMODEL_EXPORT void iterate_model(const QAbstractItemModel *model, const QModelIndex &parent, const std::function< void(const QModelIndex &child)> &fun)
Iterates through QAbstractItem model.

Referenced by ModelView::ViewModelController::ViewModelControllerImpl::findViews(), and TEST_F().

◆ join()

std::string ModelView::Utils::join ( const std::string &  part1,
const std::string &  part2 
)

Joins two path elements into the path.

Definition at line 37 of file fileutils.cpp.

38 {
39 #ifdef ENABLE_FILESYSTEM
40  auto path = std::filesystem::path(part1) / std::filesystem::path(part2);
41  return path.string();
42 #else
43  return part1 + std::string("/") + part2;
44 #endif
45 }

Referenced by FolderBasedTest::createEmptyDir(), ModelView::Project::ProjectImpl::process(), and TEST_F().

◆ MoveDown()

void ModelView::Utils::MoveDown ( SessionItem item)

Moves item down (increments row of the item). Works on children belonging to single tag.

Definition at line 71 of file modelutils.cpp.

72 {
73  auto tagrow = item->tagRow();
74  if (tagrow.row == item->parent()->itemCount(tagrow.tag) - 1)
75  return; // item already at the buttom
76  item->model()->moveItem(item, item->parent(), tagrow.next());
77 }
int itemCount(const std::string &tag) const
Returns number of items in given tag.
void moveItem(SessionItem *item, SessionItem *new_parent, const TagRow &tagrow)
Move item from it's current parent to a new parent under given tag and row.

References ModelView::SessionItem::itemCount(), ModelView::SessionItem::model(), ModelView::SessionModel::moveItem(), ModelView::SessionItem::parent(), and ModelView::SessionItem::tagRow().

Referenced by gui2::LayerEditorActions::onMoveDown(), gui2::MaterialEditorActions::onMoveDown(), and TEST_F().

Here is the call graph for this function:

◆ MoveUp()

void ModelView::Utils::MoveUp ( SessionItem item)

Moves item up (decrements row of the item). Works on children belonging to single tag.

Definition at line 63 of file modelutils.cpp.

64 {
65  auto tagrow = item->tagRow();
66  if (tagrow.row == 0)
67  return; // item already at the top
68  item->model()->moveItem(item, item->parent(), tagrow.prev());
69 }

References ModelView::SessionItem::model(), ModelView::SessionModel::moveItem(), ModelView::SessionItem::parent(), and ModelView::SessionItem::tagRow().

Referenced by gui2::LayerEditorActions::onMoveUp(), gui2::MaterialEditorActions::onMoveUp(), and TEST_F().

Here is the call graph for this function:

◆ parent_path()

std::string ModelView::Utils::parent_path ( const std::string &  path)

Returns the path to the parent directory.

Definition at line 111 of file fileutils.cpp.

112 {
113 #ifdef ENABLE_FILESYSTEM
114  return std::filesystem::path(path).parent_path().string();
115 #else
116  QFileInfo info(QString::fromStdString(path));
117  return info.dir().path().toStdString();
118 #endif
119 }

Referenced by TEST_F(), gui2::ImportFileWidget::updateCurrentWorkdir(), and gui2::RecentProjectSettings::updateWorkdirFromSelection().

◆ ParentItemsFromIndex()

std::vector< SessionItem * > ModelView::Utils::ParentItemsFromIndex ( const QModelIndexList &  index_list)

Returns vector of parent items from given index list.

Finds all SessionItems corresponding to given index list and collect their parents. Function is usefull in the context of table-like views when we want to find compound items (i.e. Layers) from table cells containing LayerItem's properties (i.e. thickness).

Definition at line 116 of file viewmodelutils.cpp.

117 {
118  std::set<SessionItem*> unique_parents;
119  for (auto item : ItemsFromIndex(index_list))
120  if (item)
121  unique_parents.insert(item->parent());
122 
123  std::vector<SessionItem*> result;
124  std::copy(unique_parents.begin(), unique_parents.end(), std::back_inserter(result));
125  return result;
126 }
MVVM_VIEWMODEL_EXPORT std::vector< SessionItem * > ItemsFromIndex(const QModelIndexList &index_list)
Returns vector of underlying SessionItem's for given index list.

References ItemsFromIndex().

Referenced by gui2::MaterialSelectionModel::selectedMaterials(), and TEST_F().

Here is the call graph for this function:

◆ PathFromItem()

Path ModelView::Utils::PathFromItem ( const SessionItem item)

Constructs path to find given item. Item must belong to a model.

Definition at line 22 of file modelutils.cpp.

23 {
24  if (!item || !item->model())
25  return {};
26 
27  Path result;
28  const SessionItem* current(item);
29  while (current && current->parent()) {
30  result.prepend(Utils::IndexOfChild(current->parent(), current));
31  current = current->parent();
32  }
33  return result;
34 }
Supports navigation through SessionModel.
Definition: path.h:35
void prepend(PathElement element)
Definition: path.cpp:62
MVVM_MODEL_EXPORT int IndexOfChild(const SessionItem *parent, const SessionItem *child)
Returns index in children array corresponding to given child.
Definition: itemutils.cpp:81

References IndexOfChild(), ModelView::SessionItem::model(), ModelView::SessionItem::parent(), and ModelView::Path::prepend().

Referenced by ModelView::AbstractItemCommand::pathFromItem(), ModelView::ViewModelController::ViewModelControllerImpl::setRootSessionItemIntern(), and TEST_F().

Here is the call graph for this function:

◆ PopulateEmptyModel()

void ModelView::Utils::PopulateEmptyModel ( const JsonModelConverterInterface converter,
const SessionModel source,
SessionModel target 
)

Populate empty model with content of target model using provided converter.

Serves as auxiliary function for model copying and cloning.

Definition at line 47 of file modelutils.cpp.

49 {
50  QJsonObject object = converter->to_json(source);
51  converter->from_json(object, target);
52 }
virtual void from_json(const QJsonObject &, SessionModel &) const =0
virtual QJsonObject to_json(const SessionModel &) const =0

References ModelView::JsonModelConverterInterface::from_json(), and ModelView::JsonModelConverterInterface::to_json().

Referenced by CreateClone(), and CreateCopy().

Here is the call graph for this function:

◆ ProjectWindowTitle()

QString ModelView::Utils::ProjectWindowTitle ( const QString &  project_dir,
bool  is_modified 
)

Returns a title composed from last part of project path, and is_modified flag.

Project without projectDir will be "Untitled", modified project will be "*Untitled".

Project with projectDir in "/home/user/project1" will get title "project1".

Definition at line 98 of file widgetutils.cpp.

99 {
100  auto pos = project_dir.lastIndexOf('/');
101  auto project_name = (pos == -1) ? untitled_name : project_dir.mid(pos + 1);
102  auto unsaved_status = is_modified ? QString("*") : QString();
103  return unsaved_status + project_name;
104 }

Referenced by gui2::ProjectPaneWidget::setCurrentProject(), TEST_F(), and gui2::ProjectHandler::updateCurrentProjectName().

◆ RandDouble()

double ModelView::Utils::RandDouble ( double  low,
double  high 
)

Produces random FLOAT values uniformly distributed on the interval [low, high).

Definition at line 38 of file numericutils.cpp.

39 {
40  std::random_device rd;
41  std::mt19937 gen(rd());
42  std::uniform_real_distribution<> uniform_real(low, high);
43  return uniform_real(gen);
44 }

◆ RandInt()

int ModelView::Utils::RandInt ( int  low,
int  high 
)

Produces random integer values uniformly distributed on the closed interval [low, high].

Definition at line 30 of file numericutils.cpp.

31 {
32  std::random_device rd;
33  std::mt19937 gen(rd());
34  std::uniform_int_distribution<int> uniform_int(low, high);
35  return uniform_int(gen);
36 }

Referenced by RandomColor().

◆ RandomColor()

QColor ModelView::Utils::RandomColor ( )

Returns random color.

Definition at line 41 of file widgetutils.cpp.

42 {
43  auto rndm = []() -> int { return ModelView::Utils::RandInt(0, 255); };
44  return QColor(rndm(), rndm(), rndm());
45 }
MVVM_MODEL_EXPORT int RandInt(int low, int high)
Produces random integer values uniformly distributed on the closed interval [low, high].

References RandInt().

Referenced by RandomNamedColor().

Here is the call graph for this function:

◆ RandomNamedColor()

std::string ModelView::Utils::RandomNamedColor ( )

Returns the name of random color.

Definition at line 47 of file widgetutils.cpp.

48 {
49  return RandomColor().name().toStdString();
50 }
MVVM_VIEW_EXPORT QColor RandomColor()
Returns random color.
Definition: widgetutils.cpp:41

References RandomColor().

Here is the call graph for this function:

◆ Real()

template<typename C >
std::vector<double> ModelView::Utils::Real ( const C &  container)

Returns vector with real part of complex numbers.

Definition at line 72 of file containerutils.h.

73 {
74  return Apply(std::begin(container), std::end(container),
75  [](const auto& x) { return std::real(x); });
76 }

References Apply().

Referenced by gui2::SpecularToySimulation::sld_profile(), and TEST_F().

Here is the call graph for this function:

◆ Redo()

void ModelView::Utils::Redo ( SessionModel model)

Redo model operation which was undone just before. If not undo/redo enabled, will do nothing.

Definition at line 85 of file modelutils.cpp.

86 {
87  if (auto stack = model.undoStack(); stack)
88  stack->redo();
89 }

References ModelView::SessionModel::undoStack().

Here is the call graph for this function:

◆ RegisteredTags()

std::vector< std::string > ModelView::Utils::RegisteredTags ( const SessionItem item)

Returns vector of strings containing all registered tags of the given item.

Definition at line 96 of file itemutils.cpp.

97 {
98  std::vector<std::string> result;
99  for (const auto container : *item.itemTags())
100  result.push_back(container->name());
101  return result;
102 }

References ModelView::SessionItem::itemTags().

Referenced by RegisteredUniversalTags(), and TEST_F().

Here is the call graph for this function:

◆ RegisteredUniversalTags()

std::vector< std::string > ModelView::Utils::RegisteredUniversalTags ( const SessionItem item)

Returns vector of strings containing all registered universal tags of the given item.

A universal tag is a tag that is usually empty after item construction and serves for later children's insertion.

Definition at line 104 of file itemutils.cpp.

105 {
106  std::vector<std::string> result;
107  for (const auto& tag : RegisteredTags(item))
108  if (!IsSinglePropertyTag(item, tag))
109  result.push_back(tag);
110  return result;
111 }
MVVM_MODEL_EXPORT std::vector< std::string > RegisteredTags(const SessionItem &item)
Returns vector of strings containing all registered tags of the given item.
Definition: itemutils.cpp:96
MVVM_MODEL_EXPORT bool IsSinglePropertyTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag, and it belongs to single property.
Definition: itemutils.cpp:91

References IsSinglePropertyTag(), and RegisteredTags().

Referenced by TEST_F().

Here is the call graph for this function:

◆ remove()

bool ModelView::Utils::remove ( const std::string &  path)

Removes file or empty directory.

Definition at line 57 of file fileutils.cpp.

58 {
59 #ifdef ENABLE_FILESYSTEM
60  return std::filesystem::remove(path);
61 #else
62  QFile file(QString::fromStdString(path));
63  return file.remove();
64 #endif
65 }
MVVM_MODEL_EXPORT bool remove(const std::string &path)
Removes file or empty directory.
Definition: fileutils.cpp:57

Referenced by LayoutUtils::removeColumn(), ParameterPool::removeParameter(), LayoutUtils::removeRow(), and TEST_F().

◆ remove_all()

void ModelView::Utils::remove_all ( const std::string &  path)

Removes directory with all its content.

Definition at line 67 of file fileutils.cpp.

68 {
69 #ifdef ENABLE_FILESYSTEM
71 #else
72  QDir dir(QString::fromStdString(path));
73  if (dir.exists())
74  dir.removeRecursively();
75 #endif
76 }
MVVM_MODEL_EXPORT void remove_all(const std::string &path)
Removes directory with all its content.
Definition: fileutils.cpp:67

Referenced by FolderBasedTest::createEmptyDir(), and TEST_F().

◆ ScaleLabelFont()

void ModelView::Utils::ScaleLabelFont ( QLabel *  label,
double  scale 
)

Set label's font size to system font size scaled by given factor.

Definition at line 141 of file widgetutils.cpp.

142 {
143  QFont font = label->font();
144  font.setPointSize(ModelView::Utils::SystemPointSize() * scale);
145  label->setFont(font);
146 }
MVVM_VIEW_EXPORT int SystemPointSize()
Returns size in points of default system font.

References SystemPointSize().

Referenced by gui2::FancyTab::FancyTab(), gui2::RecentProjectWidget::createCurrentProjectLayout(), gui2::OpenProjectWidget::createLinkedLabelLayout(), gui2::OpenProjectWidget::createProjectTitleLayout(), and gui2::RecentProjectWidget::createRecentProjectLayout().

Here is the call graph for this function:

◆ serialize()

QByteArray ModelView::Utils::serialize ( const QStringList &  data)

Converts vector of strings to byte array.

Definition at line 164 of file widgetutils.cpp.

165 {
166  QByteArray byteArray;
167  QDataStream out(&byteArray, QIODevice::WriteOnly);
168  out << data;
169  return byteArray;
170 }

Referenced by gui2::DataViewModel::mimeData(), and TEST_F().

◆ SetLogarithmicScale() [1/2]

void ModelView::Utils::SetLogarithmicScale ( QCPAxis *  axis,
bool  is_log_scale 
)

Switch axis to logarithmic scale mode.

Definition at line 29 of file customplotutils.cpp.

30 {
31  if (is_log_scale) {
32  axis->setNumberFormat("eb");
33  axis->setNumberPrecision(0);
34  axis->setScaleType(QCPAxis::stLogarithmic);
35  QSharedPointer<QCPAxisTicker> ticker(new QCPAxisTickerLog);
36  axis->setTicker(ticker);
37  } else {
38  axis->setNumberFormat("g");
39  axis->setNumberPrecision(6);
40  axis->setScaleType(QCPAxis::stLinear);
41  QSharedPointer<QCPAxisTicker> ticker(new QCPAxisTicker);
42  axis->setTicker(ticker);
43  }
44 }

◆ SetLogarithmicScale() [2/2]

void ModelView::Utils::SetLogarithmicScale ( QCPColorScale *  axis,
bool  is_log_scale 
)

Switch axis to logarithmic scale mode.

Definition at line 18 of file customplotutils.cpp.

19 {
20  if (is_log_scale && axis->dataScaleType() != QCPAxis::stLogarithmic)
21  axis->setDataScaleType(QCPAxis::stLogarithmic);
22 
23  else if (!is_log_scale && axis->dataScaleType() != QCPAxis::stLinear)
24  axis->setDataScaleType(QCPAxis::stLinear);
25 
26  SetLogarithmicScale(axis->axis(), is_log_scale);
27 }
MVVM_VIEW_EXPORT void SetLogarithmicScale(QCPColorScale *axis, bool is_log_scale)
Switch axis to logarithmic scale mode.

Referenced by ModelView::ViewportAxisPlotController::AxesPlotControllerImpl::setAxisLogScaleFromItem().

◆ SinglePropertyItems()

std::vector< SessionItem * > ModelView::Utils::SinglePropertyItems ( const SessionItem item)

Returns vector of children representing property items.

Definition at line 122 of file itemutils.cpp.

123 {
124  std::vector<SessionItem*> result;
125  for (auto child : item.children())
126  if (IsSinglePropertyTag(item, item.tagRowOfItem(child).tag))
127  result.push_back(child);
128  return result;
129 }
std::string tag
Definition: tagrow.h:27

References ModelView::SessionItem::children(), IsSinglePropertyTag(), ModelView::TagRow::tag, and ModelView::SessionItem::tagRowOfItem().

Referenced by ModelView::PropertyItemsStrategy::children(), ModelView::PropertyItemsFlatStrategy::children(), ModelView::PropertiesRowStrategy::constructRow(), and TEST_F().

Here is the call graph for this function:

◆ SizeOfLetterM()

QSize ModelView::Utils::SizeOfLetterM ( )

Returns size corresponding to actual size of letter M basing on current font metrics.

Definition at line 116 of file widgetutils.cpp.

117 {
118  static QSize result = FindSizeOfLetterM();
119  return result;
120 }

Referenced by gui2::OpenProjectWidget::OpenProjectWidget(), gui2::RecentProjectWidget::createRecentProjectScrollArea(), HeightOfLetterM(), and WidthOfLetterM().

◆ SystemPointSize()

int ModelView::Utils::SystemPointSize ( )

Returns size in points of default system font.

Definition at line 122 of file widgetutils.cpp.

123 {
124  return QApplication::font().pointSize();
125 }

Referenced by gui2::ImportTextView::ImportTextView(), and ScaleLabelFont().

◆ TextColorRole()

QVariant ModelView::Utils::TextColorRole ( const SessionItem item)

Returns text color for given item.

Definition at line 68 of file viewmodelutils.cpp.

69 {
70  return item.isEnabled() ? QVariant() : QColor(Qt::gray);
71 }
bool isEnabled() const
Returns true if this item has enabled flag set.

References ModelView::SessionItem::isEnabled().

Referenced by ModelView::PropertyFlatView::PropertyFlatViewImpl::connect_model(), ModelView::ViewItem::data(), ItemRoleToQtRole(), and TEST_F().

Here is the call graph for this function:

◆ toCustomVariant()

Variant ModelView::Utils::toCustomVariant ( const Variant standard)

Converts Qt variant to custom variant on board of SessionItem.

Definition at line 79 of file customvariants.cpp.

80 {
81  if (!standard.isValid())
82  return standard;
83 
84  // converts variant based on std::string to variant based on QString
85  if (standard.typeName() == qstring_name)
86  return Variant::fromValue(standard.toString().toStdString());
87 
88  // in other cases returns unchanged variant
89  return standard;
90 }

Referenced by ModelView::ViewItem::setData(), and TEST_F().

◆ ToolTipRole()

QVariant ModelView::Utils::ToolTipRole ( const SessionItem item)

Returns tooltip role for given item.

Definition at line 91 of file viewmodelutils.cpp.

92 {
93  return item.hasData(ItemDataRole::TOOLTIP) ? Variant(QString::fromStdString(item.toolTip()))
94  : QVariant();
95 }
bool hasData(int role=ItemDataRole::DATA) const
Returns true if item has data on board with given role.
std::string toolTip() const
Returns item tooltip, if exists.
QVariant Variant
Definition: variant.h:23

References ModelView::SessionItem::hasData(), ModelView::ItemDataRole::TOOLTIP, and ModelView::SessionItem::toolTip().

Referenced by ModelView::ViewItem::data(), and TEST_F().

Here is the call graph for this function:

◆ TopItem()

template<typename T = SessionItem>
T* ModelView::Utils::TopItem ( const SessionModel model)

Returns top level item of given type.

Definition at line 47 of file modelutils.h.

48 {
49  auto items = TopItems<T>(model);
50  return items.empty() ? nullptr : items.front();
51 }

◆ TopItems()

template<typename T = SessionItem>
std::vector<T*> ModelView::Utils::TopItems ( const SessionModel model)

Returns all top level items of given type.

Definition at line 34 of file modelutils.h.

35 {
36  std::vector<T*> result;
37  for (auto child : model->rootItem()->children()) {
38  if (auto item = dynamic_cast<T*>(child); item)
39  result.push_back(item);
40  }
41 
42  return result;
43 }
QVector< SessionItem * > children() const
Returns vector of all children.

References ModelView::SessionItem::children(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TopLevelItems()

std::vector< SessionItem * > ModelView::Utils::TopLevelItems ( const SessionItem item)

Returns vector of children representing top level items.

Definition at line 113 of file itemutils.cpp.

114 {
115  std::vector<SessionItem*> result;
116  for (auto child : item.children())
117  if (!IsSinglePropertyTag(item, item.tagRowOfItem(child).tag))
118  result.push_back(child);
119  return result;
120 }

References ModelView::SessionItem::children(), IsSinglePropertyTag(), ModelView::TagRow::tag, and ModelView::SessionItem::tagRowOfItem().

Referenced by ModelView::TopItemsStrategy::children(), and TEST_F().

Here is the call graph for this function:

◆ toQtVariant()

Variant ModelView::Utils::toQtVariant ( const Variant custom)

Converts custom variant to standard variant which Qt views will understand.

Definition at line 61 of file customvariants.cpp.

62 {
63  if (!custom.isValid())
64  return custom;
65 
66  // converts variant based on std::string to variant based on QString
67  if (custom.typeName() == Constants::string_type_name) {
68  return Variant(QString::fromStdString(custom.value<std::string>()));
69  } else if (IsDoubleVectorVariant(custom)) {
70  QString str =
71  QString("vector of %1 elements").arg(custom.value<std::vector<double>>().size());
72  return Variant(str);
73  }
74 
75  // in other cases returns unchanged variant
76  return custom;
77 }
const std::string string_type_name
MVVM_MODEL_EXPORT bool IsDoubleVectorVariant(const Variant &variant)
Returns true in the case of variant based on std::vector<double>.

References IsDoubleVectorVariant(), and ModelView::Constants::string_type_name.

Referenced by ModelView::ViewItem::data(), and TEST_F().

Here is the call graph for this function:

◆ toStringList()

QStringList ModelView::Utils::toStringList ( const std::vector< std::string > &  vec)

Converts vector of strings to QStringList.

Definition at line 148 of file widgetutils.cpp.

149 {
150  QStringList result;
151  for (const auto& x : vec)
152  result.push_back(QString::fromStdString(x));
153  return result;
154 }

Referenced by gui2::DataLoaderDialog::setTargetCanvas(), and TEST_F().

◆ Undo()

void ModelView::Utils::Undo ( SessionModel model)

Undo last model operation. If not undo/redo enabled, will do nothing.

Definition at line 79 of file modelutils.cpp.

80 {
81  if (auto stack = model.undoStack(); stack)
82  stack->undo();
83 }

References ModelView::SessionModel::undoStack().

Here is the call graph for this function:

◆ UniqueItems()

std::vector< SessionItem * > ModelView::Utils::UniqueItems ( const std::vector< SessionItem * > &  items)

Returns vector with duplicates and 'nullptr' filtered out.

Definition at line 170 of file itemutils.cpp.

171 {
172  auto filtered = Utils::UniqueWithOrder(items);
173  std::vector<SessionItem*> result;
174  std::copy_if(filtered.begin(), filtered.end(), std::back_inserter(result),
175  [](auto x) { return x != nullptr; });
176  return result;
177 }
C UniqueWithOrder(const C &container)
Returns copy of container with all duplicated elements filtered our. The order is preserved.

References UniqueWithOrder().

Referenced by gui2::DataSelectionModel::selectedItems(), TEST_F(), and UniqueItemsFromIndex().

Here is the call graph for this function:

◆ UniqueItemsFromIndex()

std::vector< SessionItem * > ModelView::Utils::UniqueItemsFromIndex ( const QModelIndexList &  index_list)

Returns vector of underlying SessionItem's for given index list. Removes repetitions.

Definition at line 111 of file viewmodelutils.cpp.

112 {
113  return Utils::UniqueItems(Utils::ItemsFromIndex(index_list));
114 }
MVVM_MODEL_EXPORT std::vector< SessionItem * > UniqueItems(const std::vector< SessionItem * > &items)
Returns vector with duplicates and 'nullptr' filtered out.
Definition: itemutils.cpp:170

References ItemsFromIndex(), and UniqueItems().

Referenced by gui2::DataViewModel::mimeData(), and TEST_F().

Here is the call graph for this function:

◆ UniqueWithOrder()

template<typename C >
C ModelView::Utils::UniqueWithOrder ( const C &  container)

Returns copy of container with all duplicated elements filtered our. The order is preserved.

Definition at line 88 of file containerutils.h.

89 {
90  C result;
91 
92  using valueType = typename C::value_type;
93  std::unordered_set<valueType> unique;
94 
95  std::copy_if(container.begin(), container.end(), std::back_inserter(result),
96  [&unique](auto x) { return unique.insert(x).second; });
97 
98  return result;
99 }

Referenced by TEST_F(), and UniqueItems().

◆ VariantName()

std::string ModelView::Utils::VariantName ( const Variant variant)

Returns name of variant.

Definition at line 26 of file customvariants.cpp.

27 {
28  return variant.isValid() ? variant.typeName() : Constants::invalid_type_name;
29 }
const std::string invalid_type_name

References ModelView::Constants::invalid_type_name.

Referenced by ModelView::VariantDependentEditorFactory::createEditor(), ModelView::JsonVariantConverter::get_json(), and TEST_F().

◆ VariantType()

int ModelView::Utils::VariantType ( const Variant variant)

Returns type of variant (additionally checks for user type).

Definition at line 31 of file customvariants.cpp.

32 {
33  auto result = static_cast<int>(variant.type());
34  if (result == Variant::UserType)
35  result = variant.userType();
36  return result;
37 }

Referenced by CompatibleVariantTypes(), and TEST_F().

◆ WidthOfLetterM()

int ModelView::Utils::WidthOfLetterM ( )

Returns width of the letter 'M' deduced from current font metrics.

Definition at line 106 of file widgetutils.cpp.

107 {
108  return ModelView::Utils::SizeOfLetterM().width();
109 }

References SizeOfLetterM().

Referenced by gui2::SettingsView::SettingsView(), gui2::ParserPropertyWidget::addCustomSeparatorRow(), gui2::OpenProjectWidget::createLinkedLabelLayout(), gui2::SettingsView::init_list_selector(), and ModelView::StatusLabel::paintEvent().

Here is the call graph for this function:

◆ WithTildeHomePath()

QString ModelView::Utils::WithTildeHomePath ( const QString &  path)

Returns a string where Linux path to the file is striped using '~/'.

Definition at line 79 of file widgetutils.cpp.

80 {
82  return path;
83 
84  static const QString homePath = QDir::homePath();
85 
86  QFileInfo fi(QDir::cleanPath(path));
87  QString outPath = fi.absoluteFilePath();
88  if (outPath.startsWith(homePath))
89  outPath = QLatin1Char('~') + outPath.mid(homePath.size());
90  else
91  outPath = path;
92  return outPath;
93 }
MVVM_VIEW_EXPORT bool IsWindowsHost()
Returns true if it is Windows.
Definition: widgetutils.cpp:52

References IsWindowsHost().

Referenced by gui2::ActionManager::aboutToShowFileMenu(), gui2::ProjectPaneWidget::setCurrentProject(), and TEST_F().

Here is the call graph for this function: