diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index c6bee22b..e7a6b4a8 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -196,6 +196,27 @@ void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors c QSqlDatabase::removeDatabase(_databasePath); } +bool ReadingListModel::isEditable(const QModelIndex &mi) +{ + return (mi.row() > specialLists.count()); +} + +QString ReadingListModel::name(const QModelIndex &mi) +{ + return data(mi,Qt::DisplayRole).toString(); +} + +void ReadingListModel::rename(const QModelIndex &mi, const QString &name) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + //TODO + + emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); + + QSqlDatabase::removeDatabase(_databasePath); +} + void ReadingListModel::deleteItem(const QModelIndex &mi) { diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index 02ad61d8..88c69692 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -33,8 +33,10 @@ public: //Convenience methods void setupModelData(QString path); - void addNewLabel(const QString & name, YACReader::LabelColors color); + bool isEditable(const QModelIndex & mi); + QString name(const QModelIndex & mi); + void rename(const QModelIndex & mi, const QString & name); signals: diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index efd1cdca..1dec58c2 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -205,9 +205,11 @@ void LibraryWindow::doLayout() foldersTitle->addAction(colapseAllNodesAction); readingListsTitle->addAction(addReadingListAction); - readingListsTitle->addAction(deleteReadingListAction); - readingListsTitle->addSepartor(); + //readingListsTitle->addSepartor(); readingListsTitle->addAction(addLabelAction); + //readingListsTitle->addSepartor(); + readingListsTitle->addAction(renameListAction); + readingListsTitle->addAction(deleteReadingListAction); readingListsTitle->addSpacing(3); //FINAL LAYOUT------------------------------------------------------------- @@ -353,7 +355,8 @@ void LibraryWindow::setUpShortcutsManagement() tmpList = QList() << addReadingListAction << deleteReadingListAction - << addLabelAction); + << addLabelAction + << renameListAction); allActions << tmpList; editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"), @@ -731,6 +734,12 @@ void LibraryWindow::createActions() addLabelAction->setToolTip(tr("Add a new label to this library")); addLabelAction->setIcon(QIcon(":/images/addLabelIcon.png")); + renameListAction = new QAction(tr("Rename selected list"), this); + renameListAction->setData(RENAME_LIST_ACTION_YL); + renameListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RENAME_LIST_ACTION_YL)); + renameListAction->setToolTip(tr("Rename any selected labels or lists")); + renameListAction->setIcon(QIcon(":/images/addLabelIcon.png")); + //disable actions disableAllActions(); } @@ -1154,6 +1163,7 @@ void LibraryWindow::createConnections() connect(addReadingListAction,SIGNAL(triggered()),this,SLOT(addNewReadingList())); connect(deleteReadingListAction,SIGNAL(triggered()),this,SLOT(deleteSelectedReadingList())); connect(addLabelAction,SIGNAL(triggered()),this,SLOT(showAddNewLabelDialog())); + connect(renameListAction,SIGNAL(triggered()),this,SLOT(showRenameCurrentList())); } void LibraryWindow::loadLibrary(const QString & name) @@ -1640,6 +1650,27 @@ void LibraryWindow::showAddNewLabelDialog() } } +//TODO implement editors in treeview +void LibraryWindow::showRenameCurrentList() +{ + QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); + if(!selectedLists.isEmpty()) + { + QModelIndex mi = selectedLists.at(0); + if(listsModel->isEditable(mi)) + { + bool ok; + QString newListName = QInputDialog::getText(this, tr("Rename list name"), + tr("List name:"), QLineEdit::Normal, + listsModel->name(mi), &ok); + + if(ok) + listsModel->rename(mi,newListName); + } + } + +} + void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child) { QModelIndex dest = foldersModel->index(child,0,mi); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index a8c588e8..367e05b9 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -202,6 +202,7 @@ private: QAction * addReadingListAction; QAction * deleteReadingListAction; QAction * addLabelAction; + QAction * renameListAction; //-- //QAction * expandAllNodesRLAction; //QAction * colapseAllNodesRLAction; @@ -370,6 +371,7 @@ public slots: void addNewReadingList(); void deleteSelectedReadingList(); void showAddNewLabelDialog(); + void showRenameCurrentList(); }; diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index cdeacd58..609ee57d 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -78,6 +78,7 @@ public: #define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL" #define REMOVE_READING_LIST_ACTION_YL "REMOVE_READING_LIST_ACTION_YL" #define ADD_LABEL_ACTION_YL "ADD_LABEL_ACTION_YL" +#define RENAME_LIST_ACTION_YL "RENAME_LIST_ACTION_YL" //COMMANDS YACReaderLibrary