Skip to content

Commit

Permalink
refactor: [toolchain] Optimize the CMake toolchain configuration
Browse files Browse the repository at this point in the history
as title

Log: Optimize toolchain configuration
  • Loading branch information
Kakueeen authored and deepin-mozart committed Jul 29, 2024
1 parent 410d290 commit e357e32
Show file tree
Hide file tree
Showing 35 changed files with 1,999 additions and 1,204 deletions.
2 changes: 1 addition & 1 deletion src/plugins/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_library(${PROJECT_NAME}
${CXX_FILES}
${QT_THEME}
${CXX_QRC}
)
)

target_link_libraries(${PROJECT_NAME}
framework
Expand Down
92 changes: 92 additions & 0 deletions src/plugins/cxx/cmake/model/kitlistmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "kitlistmodel.h"

#include <QUuid>

KitListModel::KitListModel(QObject *parent)
: QAbstractItemModel(parent)
{
}

int KitListModel::columnCount(const QModelIndex &parent) const
{
return 1;
}

QVariant KitListModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= kitItemList.size())
return {};

switch (role) {
case Qt::ToolTipRole:
case Qt::DisplayRole:
return kitItemList.value(index.row()).kitName();
default:
break;
}

return {};
}

QModelIndex KitListModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent)

if (column == 0 && row < kitItemList.size()) {
const auto &item = kitItemList.at(row);
return createIndex(row, 0, const_cast<Kit *>(&item));
}

return {};
}

QModelIndex KitListModel::parent(const QModelIndex &child) const
{
return {};
}

int KitListModel::rowCount(const QModelIndex &parent) const
{
return kitItemList.size();
}

Kit *KitListModel::itemForIndex(const QModelIndex &index)
{
return static_cast<Kit *>(index.internalPointer());
}

void KitListModel::setItemList(const QList<Kit> &itemList)
{
beginResetModel();
kitItemList = itemList;
endResetModel();
}

QModelIndex KitListModel::addItem()
{
Kit item;
item.setKitName(tr("Unnamed"));

int pos = kitItemList.size();
beginInsertRows(QModelIndex(), pos, pos);
kitItemList.append(item);
endInsertRows();

return index(pos, 0);
}

void KitListModel::removeItem(const QModelIndex &index)
{
auto item = itemForIndex(index);
if (!item)
return;

int pos = kitItemList.indexOf(*item);
beginRemoveRows(QModelIndex(), pos, pos);
kitItemList.removeAt(pos);
endRemoveRows();
}
35 changes: 35 additions & 0 deletions src/plugins/cxx/cmake/model/kitlistmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef KITLISTMODEL_H
#define KITLISTMODEL_H

#include "global_define.h"
#include "cmake/option/kit.h"

#include <QAbstractItemModel>

class KitListModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit KitListModel(QObject *parent = nullptr);

int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

Kit *itemForIndex(const QModelIndex &index);
void setItemList(const QList<Kit> &itemList);
QList<Kit> itemList() const { return kitItemList; }
QModelIndex addItem();
void removeItem(const QModelIndex &index);

private:
QList<Kit> kitItemList;
};

#endif // KITLISTMODEL_H
77 changes: 0 additions & 77 deletions src/plugins/cxx/cmake/option/cmakeoptionwidget.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/plugins/cxx/cmake/option/cmakeoptionwidget.h

This file was deleted.

Loading

0 comments on commit e357e32

Please sign in to comment.