Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [toolchain] Optimize the CMake toolchain configuration #843

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading