Skip to content

Commit

Permalink
Changed template class
Browse files Browse the repository at this point in the history
  • Loading branch information
juliagoda committed Jan 12, 2024
1 parent b324bd7 commit c764ce5
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 103 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

project(pak-gui VERSION ${VERSION} LANGUAGES CXX)

if(POLICY CMP0153)
cmake_policy(SET CMP0153 NEW)
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
Expand Down Expand Up @@ -44,7 +48,7 @@ endif()

find_package(pak REQUIRED)
find_package(pacman-contrib REQUIRED)
find_package(kdesu REQUIRED)
find_package(kdesu5 REQUIRED)
find_package(ksshaskpass REQUIRED)
find_package(bash REQUIRED)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets Charts Concurrent Network)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findauracle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(AURACLE_FOUND 1)
set(AURACLE_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi auracle-git OUTPUT_VARIABLE AURACLE_INFO)
execute_process(COMMAND ${PACMAN} -Qi auracle-git OUTPUT_VARIABLE AURACLE_INFO)

if(${AURACLE_INFO} STREQUAL "error: package 'auracle-git' was not found")
set(AURACLE_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findbash.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(BASH_FOUND 1)
set(BASH_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi bash OUTPUT_VARIABLE BASH_INFO)
execute_process(COMMAND ${PACMAN} -Qi bash OUTPUT_VARIABLE BASH_INFO)

if(${BASH_INFO} STREQUAL "error: package 'bash' was not found")
set(BASH_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Finddevtools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(DEVTOOLS_FOUND 1)
set(DEVTOOLS_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi devtools OUTPUT_VARIABLE DEVTOOLS_INFO)
execute_process(COMMAND ${PACMAN} -Qi devtools OUTPUT_VARIABLE DEVTOOLS_INFO)

if(${DEVTOOLS_INFO} STREQUAL "error: package 'devtools' was not found")
set(DEVTOOLS_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Finddowngrade.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(DOWNGRADE_FOUND 1)
set(DOWNGRADE_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi downgrade OUTPUT_VARIABLE DOWNGRADE_INFO)
execute_process(COMMAND ${PACMAN} -Qi downgrade OUTPUT_VARIABLE DOWNGRADE_INFO)

if(${DOWNGRADE_INFO} STREQUAL "error: package 'downgrade' was not found")
set(DOWNGRADE_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findfzf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(FZF_FOUND 1)
set(FZF_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi fzf OUTPUT_VARIABLE FZF_INFO)
execute_process(COMMAND ${PACMAN} -Qi fzf OUTPUT_VARIABLE FZF_INFO)

if(${FZF_INFO} STREQUAL "error: package 'fzf' was not found")
set(FZF_FOUND 0)
Expand Down
11 changes: 0 additions & 11 deletions packages/Findkdesu.cmake

This file was deleted.

11 changes: 11 additions & 0 deletions packages/Findkdesu5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

set(KDESU5_FOUND 1)
set(KDESU5_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
execute_process(COMMAND ${PACMAN} -Qi kdesu5 OUTPUT_VARIABLE KDESU5_INFO)

if(${KDESU5_INFO} STREQUAL "error: package 'kdesu5' was not found")
set(KDESU5_FOUND 0)
endif()

2 changes: 1 addition & 1 deletion packages/Findlibnotify.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(LIBNOTIFY_FOUND 1)
set(LIBNOTIFY_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi libnotify OUTPUT_VARIABLE LIBNOTIFY_INFO)
execute_process(COMMAND ${PACMAN} -Qi libnotify OUTPUT_VARIABLE LIBNOTIFY_INFO)

if(${LIBNOTIFY_INFO} STREQUAL "error: package 'libnotify' was not found")
set(LIBNOTIFY_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findnamcap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(NAMCAP_FOUND 1)
set(NAMCAP_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin )
exec_program(${PACMAN} ARGS -Qi namcap OUTPUT_VARIABLE NAMCAP_INFO)
execute_process(COMMAND ${PACMAN} -Qi namcap OUTPUT_VARIABLE NAMCAP_INFO)

if(${NAMCAP_INFO} STREQUAL "error: package 'namcap' was not found")
set(NAMCAP_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findpacman-contrib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(PACMAN-CONTRIB_FOUND 1)
set(PACMAN_CONTRIB_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi pacman-contrib OUTPUT_VARIABLE PACMAN_CONTRIB_INFO)
execute_process(COMMAND ${PACMAN} -Qi pacman-contrib OUTPUT_VARIABLE PACMAN_CONTRIB_INFO)

if(${PACMAN_CONTRIB_INFO} STREQUAL "error: package 'pacman-contrib' was not found")
set(PACMAN-CONTRIB_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findreflector.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(REFLECTOR_FOUND 1)
set(REFLECTOR_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin )
exec_program(${PACMAN} ARGS -Qi reflector OUTPUT_VARIABLE REFLECTOR_INFO)
execute_process(COMMAND ${PACMAN} -Qi reflector OUTPUT_VARIABLE REFLECTOR_INFO)

if(${REFLECTOR_INFO} STREQUAL "error: package 'reflector' was not found")
set(REFLECTOR_FOUND 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/Findsubversion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(SUBVERSION_FOUND 1)
set(SUBVERSION_INFO "")

find_program(PACMAN pacman /bin /usr/bin /usr/local/bin)
exec_program(${PACMAN} ARGS -Qi subversion OUTPUT_VARIABLE SUBVERSION_INFO)
execute_process(COMMAND ${PACMAN} -Qi subversion OUTPUT_VARIABLE SUBVERSION_INFO)

if(${SUBVERSION_INFO} STREQUAL "error: package 'subversion' was not found")
set(SUBVERSION_FOUND 0)
Expand Down
91 changes: 31 additions & 60 deletions src/src/algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@

#include "package.h"

// TODOJG - reduce parameters list

template class Algorithms<Package::TooltipLine>;


template<typename T>
Algorithms<T>::Algorithms(const QString& new_separator,
const QList<T>& new_list,
const QHash<int, T>& new_map) :
separator{new_separator}, list{new_list}, map{new_map}
{
// ...
}


template<typename T>
QStringList Algorithms::createSplittedList(const QString& text,
const QString& separator,
const QList<T>& list,
const QHash<int, T>& map)
QStringList Algorithms<T>::createSplittedList(const QString& text)
{
QStringList selected_infos{};
int selected_info_size = list.count();
Expand All @@ -41,17 +51,14 @@ QStringList Algorithms::createSplittedList(const QString& text,
if (text.isEmpty() || selected_infos.isEmpty())
return QStringList();

createListOfLines<T>(selected_infos, text, separator, list, map);
createListOfLines(selected_infos, text);
return selected_infos;
}

// TODOJG - reduce parameters list

template<typename T>
void Algorithms::createListOfLines(QStringList& selected_infos,
const QString& text,
const QString& separator,
const QList<T>& list,
const QHash<int, T>& map)
void Algorithms<T>::createListOfLines(QStringList& selected_infos,
const QString& text)
{
const auto& lines_list = text.split('\n');
int i = 0;
Expand All @@ -60,7 +67,7 @@ void Algorithms::createListOfLines(QStringList& selected_infos,

std::for_each(lines_list.begin(), lines_list.end(), [&](const QString& line)
{
if (foundIndexOdSeparator<T>(line, separator, index_of_separator, list, map, i, selected_infos, last_index))
if (foundIndexOdSeparator(line, index_of_separator, i, selected_infos, last_index))
return line;

if (last_index < 0)
Expand All @@ -72,35 +79,31 @@ void Algorithms::createListOfLines(QStringList& selected_infos,
});
}

// TODOJG - reduce parameters list

template<typename T>
bool Algorithms::foundIndexOdSeparator(const QString& line,
const QString& separator,
int& index_of_separator,
const QList<T>& list,
const QHash<int, T>& map,
int& i,
QStringList& selected_infos,
int& last_index)
bool Algorithms<T>::foundIndexOdSeparator(const QString& line,
int& index_of_separator,
int& i,
QStringList& selected_infos,
int& last_index)
{
if (line.contains(separator))
{
i++;
index_of_separator = line.indexOf(separator) + separator.count();
auto tooltip_part = map.value(i);
last_index = getFirstIndexAfterSeparator<T>(list, tooltip_part, selected_infos, line);
last_index = getFirstIndexAfterSeparator(tooltip_part, selected_infos, line);
return true;
}

return false;
}

// TODOJG - reduce parameters list

template<typename T>
int Algorithms::getFirstIndexAfterSeparator(const QList<T>& list,
T tooltip_part,
QStringList& selected_infos,
const QString& line)
int Algorithms<T>::getFirstIndexAfterSeparator(T tooltip_part,
QStringList& selected_infos,
const QString& line)
{
if (list.contains(tooltip_part))
{
Expand All @@ -110,35 +113,3 @@ int Algorithms::getFirstIndexAfterSeparator(const QList<T>& list,

return -1;
}


// forward declarations
// TODOJG - maybe better class template

template QStringList Algorithms::createSplittedList(const QString& text,
const QString& separator,
const QList<Package::TooltipLine>& list,
const QHash<int, Package::TooltipLine>& map);

template void Algorithms::createListOfLines(QStringList& selected_infos,
const QString& text,
const QString& separator,
const QList<Package::TooltipLine>& list,
const QHash<int, Package::TooltipLine>& map);

template bool Algorithms::foundIndexOdSeparator(const QString& line_it,
const QString& separator,
int& index_of_separator,
const QList<Package::TooltipLine>& list,
const QHash<int, Package::TooltipLine>& map,
int& i,
QStringList& selected_infos,
int& last_index);

template int Algorithms::getFirstIndexAfterSeparator(const QList<Package::TooltipLine>& list,
Package::TooltipLine tooltip_part,
QStringList& selected_infos,
const QString& line);



29 changes: 12 additions & 17 deletions src/src/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,33 @@
#include <QStringList>
#include <QMap>

template<typename T>
class Algorithms
{
public:
template<typename T>
QStringList createSplittedList(const QString& text,
const QString& separator,
const QList<T>& list,
const QHash<int, T>& map);
explicit Algorithms(const QString& separator,
const QList<T>& list,
const QHash<int, T>& map);

QStringList createSplittedList(const QString& text);

private:
template<typename T>
void createListOfLines(QStringList& selected_infos,
const QString& text,
const QString& separator,
const QList<T>& list,
const QHash<int, T>& map);
const QString& text);


template<typename T>
bool foundIndexOdSeparator(const QString& line,
const QString& separator,
int& index_of_separator,
const QList<T>& list,
const QHash<int, T>& map,
int& i,
QStringList& selected_infos,
int& last_index);

template<typename T>
int getFirstIndexAfterSeparator(const QList<T>& list,
T tooltip_part,
int getFirstIndexAfterSeparator(T tooltip_part,
QStringList& selected_infos,
const QString& line);

const QString separator;
const QList<T> list;
const QHash<int, T> map;
};

8 changes: 4 additions & 4 deletions src/src/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ void Package::setVersionParameter(int parameter_line,
void Package::setToolTipOnPackage(const QString& text)
{
auto selected_info_list = Settings::records()->packagesInfoSelected();

QScopedPointer<Algorithms> algorithms(new Algorithms);
QString splitting_text{" : "};
Constants constants;
const auto& results = algorithms->createSplittedList<Package::TooltipLine>(text, splitting_text,
selected_info_list, constants.typePackageToTooltipLines(getType()));

QScopedPointer<Algorithms<Package::TooltipLine>> algorithms(new Algorithms{splitting_text,
selected_info_list, constants.typePackageToTooltipLines(getType())});
const auto& results = algorithms->createSplittedList(text);

setToolTip(results.join(QString("\n")));
}
Expand Down

0 comments on commit c764ce5

Please sign in to comment.