editing names in lists (not finished)

This commit is contained in:
Luis Ángel San Martín 2014-11-11 18:02:29 +01:00
parent d1fbb1d5ba
commit c6722cae2c
5 changed files with 61 additions and 4 deletions

View File

@ -196,6 +196,27 @@ void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors c
QSqlDatabase::removeDatabase(_databasePath); 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) void ReadingListModel::deleteItem(const QModelIndex &mi)
{ {

View File

@ -33,8 +33,10 @@ public:
//Convenience methods //Convenience methods
void setupModelData(QString path); void setupModelData(QString path);
void addNewLabel(const QString & name, YACReader::LabelColors color); 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: signals:

View File

@ -205,9 +205,11 @@ void LibraryWindow::doLayout()
foldersTitle->addAction(colapseAllNodesAction); foldersTitle->addAction(colapseAllNodesAction);
readingListsTitle->addAction(addReadingListAction); readingListsTitle->addAction(addReadingListAction);
readingListsTitle->addAction(deleteReadingListAction); //readingListsTitle->addSepartor();
readingListsTitle->addSepartor();
readingListsTitle->addAction(addLabelAction); readingListsTitle->addAction(addLabelAction);
//readingListsTitle->addSepartor();
readingListsTitle->addAction(renameListAction);
readingListsTitle->addAction(deleteReadingListAction);
readingListsTitle->addSpacing(3); readingListsTitle->addSpacing(3);
//FINAL LAYOUT------------------------------------------------------------- //FINAL LAYOUT-------------------------------------------------------------
@ -353,7 +355,8 @@ void LibraryWindow::setUpShortcutsManagement()
tmpList = QList<QAction *>() tmpList = QList<QAction *>()
<< addReadingListAction << addReadingListAction
<< deleteReadingListAction << deleteReadingListAction
<< addLabelAction); << addLabelAction
<< renameListAction);
allActions << tmpList; allActions << tmpList;
editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"), 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->setToolTip(tr("Add a new label to this library"));
addLabelAction->setIcon(QIcon(":/images/addLabelIcon.png")); 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 //disable actions
disableAllActions(); disableAllActions();
} }
@ -1154,6 +1163,7 @@ void LibraryWindow::createConnections()
connect(addReadingListAction,SIGNAL(triggered()),this,SLOT(addNewReadingList())); connect(addReadingListAction,SIGNAL(triggered()),this,SLOT(addNewReadingList()));
connect(deleteReadingListAction,SIGNAL(triggered()),this,SLOT(deleteSelectedReadingList())); connect(deleteReadingListAction,SIGNAL(triggered()),this,SLOT(deleteSelectedReadingList()));
connect(addLabelAction,SIGNAL(triggered()),this,SLOT(showAddNewLabelDialog())); connect(addLabelAction,SIGNAL(triggered()),this,SLOT(showAddNewLabelDialog()));
connect(renameListAction,SIGNAL(triggered()),this,SLOT(showRenameCurrentList()));
} }
void LibraryWindow::loadLibrary(const QString & name) 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) void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child)
{ {
QModelIndex dest = foldersModel->index(child,0,mi); QModelIndex dest = foldersModel->index(child,0,mi);

View File

@ -202,6 +202,7 @@ private:
QAction * addReadingListAction; QAction * addReadingListAction;
QAction * deleteReadingListAction; QAction * deleteReadingListAction;
QAction * addLabelAction; QAction * addLabelAction;
QAction * renameListAction;
//-- //--
//QAction * expandAllNodesRLAction; //QAction * expandAllNodesRLAction;
//QAction * colapseAllNodesRLAction; //QAction * colapseAllNodesRLAction;
@ -370,6 +371,7 @@ public slots:
void addNewReadingList(); void addNewReadingList();
void deleteSelectedReadingList(); void deleteSelectedReadingList();
void showAddNewLabelDialog(); void showAddNewLabelDialog();
void showRenameCurrentList();
}; };

View File

@ -78,6 +78,7 @@ public:
#define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL" #define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL"
#define REMOVE_READING_LIST_ACTION_YL "REMOVE_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 ADD_LABEL_ACTION_YL "ADD_LABEL_ACTION_YL"
#define RENAME_LIST_ACTION_YL "RENAME_LIST_ACTION_YL"
//COMMANDS YACReaderLibrary //COMMANDS YACReaderLibrary