| 1 | /* |
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #include "macroinfomodel.h" |
| 18 | |
| 19 | MacroInfoModel::MacroInfoModel(QObject *parent) : QAbstractListModel(parent) |
| 20 | { |
| 21 | addMacroInfo("<DEFAULT>" , tr("The default directory" )); |
| 22 | addMacroInfo("<DEVCPP>" , tr("Path to the Red Panda C++'s executable file." )); |
| 23 | addMacroInfo("<DEVCPPVERSION>" , tr("Version of the Red Panda C++" )); |
| 24 | addMacroInfo("<EXECPATH>" , tr("PATH to the Red Panda C++'s installation folder." )); |
| 25 | addMacroInfo("<DATE>" , tr("Current date" )); |
| 26 | addMacroInfo("<DATETIME>" , tr("Current date and time" )); |
| 27 | addMacroInfo("<INCLUDE>" , tr("The first include directory of the working compiler set." )); |
| 28 | addMacroInfo("<LIB>" , tr("The first lib directory of the working compiler set." )); |
| 29 | addMacroInfo("<EXENAME>" , tr("The compiled filename" )); |
| 30 | addMacroInfo("<EXEFILE>" , tr("Full path to the compiled file" )); |
| 31 | addMacroInfo("<SOURCENAME>" , tr("Filename of the current source file" )); |
| 32 | addMacroInfo("<SOURCEFILE>" , tr("Full path to the current source file" )); |
| 33 | addMacroInfo("<SOURCEPATH>" , tr("Path to the current source file's parent folder" )); |
| 34 | addMacroInfo("<WORDXY>" , tr("Word at the cursor in the active editor" )); |
| 35 | addMacroInfo("<PROJECTNAME>" , tr("Name of the current project" )); |
| 36 | addMacroInfo("<PROJECTFILE>" , tr("Full path to the current project file" )); |
| 37 | addMacroInfo("<PROJECTFILENAME>" , tr("Name of the current project file" )); |
| 38 | addMacroInfo("<PROJECTPATH>" , tr("Path to the current project's folder" )); |
| 39 | } |
| 40 | |
| 41 | int MacroInfoModel::rowCount(const QModelIndex &/*parent*/) const |
| 42 | { |
| 43 | return mMacroInfos.count(); |
| 44 | } |
| 45 | |
| 46 | QVariant MacroInfoModel::data(const QModelIndex &index, int role) const |
| 47 | { |
| 48 | if (!index.isValid()) |
| 49 | return QVariant(); |
| 50 | if (role == Qt::DisplayRole) { |
| 51 | PMacroInfo info = mMacroInfos[index.row()]; |
| 52 | return info->description; |
| 53 | } else if (role == Qt::UserRole) { |
| 54 | PMacroInfo info = mMacroInfos[index.row()]; |
| 55 | return info->macro; |
| 56 | } |
| 57 | return QVariant(); |
| 58 | } |
| 59 | |
| 60 | PMacroInfo MacroInfoModel::getInfo(const QModelIndex &index) const |
| 61 | { |
| 62 | if (!index.isValid()) |
| 63 | return PMacroInfo(); |
| 64 | return mMacroInfos[index.row()]; |
| 65 | } |
| 66 | |
| 67 | void MacroInfoModel::addMacroInfo(const QString& macro, const QString& description) { |
| 68 | PMacroInfo info = std::make_shared<MacroInfo>(); |
| 69 | info->macro = macro; |
| 70 | info->description = description; |
| 71 | mMacroInfos.append(info); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | |